
Security News
The Nightmare Before Deployment
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.
pytest-json
Advanced tools
.. image:: https://travis-ci.org/mattcl/pytest-json.svg?branch=master :target: https://travis-ci.org/mattcl/pytest-json :alt: See Build Status on Travis CI
pytest-json is a plugin for py.test <http://pytest.org>_ that generates JSON
reports for test results
This Pytest_ plugin was generated with Cookiecutter_ along with
@hackebrot's Cookiecutter-pytest-plugin template.
You can install "pytest-json" via pip_ from PyPI_::
$ pip install pytest-json
.. code-block::
$ py.test --json=report.json
or you can set the report path in an ini file::
[pytest] json_report = report.json
The command-line option will override the ini file
There is an optional flag to normalize the generated report to
jsonapi <http://jsonapi.org>_. This is intended for (easier) consumption by
ember-data and others::
$ py.test --json=report.json --jsonapi
or you can set the jsonapi flag in an ini file::
[pytest] jsonapi = anything
Note that the value of the ini var can be anything. Presence alone will cause it to be true.
You can modify request.config._json_environment in a fixture
.. code-block:: python
@pytest.fixture(scope='session', autouse=True): def extra_json_environment(request): request.config._json_environment.append(('herp', 'derp'))
Metadata added via stage_metadata shows up in metadata field of the
stage in the resulting JSON object
.. code-block:: python
@pytest.hookimpl(tryfirst=True, hookwrapper=True) def pytest_runtest_makereport(item, call): outcome = yield report = outcome.get_result() if report.when == 'call': report.stage_metadata = { 'foo': 'bar' } elif report.when == 'setup': report.stage_metadata = { 'hoof': 'doof' } elif report.when == 'teardown': report.stage_metadata = { 'herp': 'derp' }
Metadata added on the tests themselves are represented by an array. To avoid
collisions, etc. Any stage (setup, teardown, call) that sets test_metadata
on a report will have its metadata appended to the array. Metadata added via
test_metadata ends up in the metadata field of the test in the
resulting JSON object
.. code-block:: python
@pytest.hookimpl(tryfirst=True, hookwrapper=True) def pytest_runtest_makereport(item, call): outcome = yield report = outcome.get_result() # only add this during call instead of during any stage if report.when == 'call': report.test_metadata = 'whatever'
To avoid issues with pytest-html, pytest-json uses
request.config._json_environment instead of request.config._environment
Additionally, pytest-json ignores the extra field on reports.
A formatted example of the output can be found in example.json
The actual output is not formatted, but this was passed through jq for readability.
A formatted example of the jsonapi output can be found in example_jsonapi.json
Contributions are very welcome. Tests can be run with tox_, please ensure
the coverage at least stays the same before you submit a pull request.
Distributed under the terms of the MIT_ license, "pytest-json" is free and open source software
If you encounter any problems, please file an issue_ along with a detailed description.
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _@hackebrot: https://github.com/hackebrot
.. _MIT: http://opensource.org/licenses/MIT
.. _BSD-3: http://opensource.org/licenses/BSD-3-Clause
.. _GNU GPL v3.0: http://www.gnu.org/licenses/gpl-3.0.txt
.. _cookiecutter-pytest-plugin: https://github.com/pytest-dev/cookiecutter-pytest-plugin
.. _file an issue: https://github.com/mattcl/pytest-json/issues
.. _pytest: https://github.com/pytest-dev/pytest
.. _tox: https://tox.readthedocs.org/en/latest/
.. _pip: https://pypi.python.org/pypi/pip/
.. _PyPI: https://pypi.python.org/pypi
FAQs
Generate JSON test reports
We found that pytest-json demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.

Research
/Security News
Impostor NuGet package Tracer.Fody.NLog typosquats Tracer.Fody and its author, using homoglyph tricks, and exfiltrates Stratis wallet JSON/passwords to a Russian IP address.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.