Skip to main content

pytest plugin for test session metadata

Project description


pytest-metadata is a plugin for `pytest <>`_ that provides
access to test session metadata.

.. image::
:alt: License
.. image::
:alt: PyPI
.. image::
.. image::
:alt: Travis
.. image::
:alt: Issues
.. image::
:alt: Requirements


You will need the following prerequisites in order to use pytest-metadata:

- Python 2.7, 3.6, PyPy, or PyPy3


To install pytest-metadata:

.. code-block:: bash

$ pip install pytest-metadata


To contribute to pytest-metadata it helps to
have `Pipenv <>`_
and `pre-commit <>`_ installed.

.. code-block:: bash

$ pipenv install --dev
$ pre-commit install

Running Tests

We use `Tox <>`_ to manage running tests
against the supported Python versions.

.. code-block:: bash

$ pipenv run tox

Available metadata

The following metadata is gathered by this plugin:

======== =============== ===================================
Key Description Example
======== =============== ===================================
Python Python version 3.6.4
Platform Platform Darwin-17.4.0-x86_64-i386-64bit
Packages pytest packages {'py': '1.5.2', 'pytest': '3.4.1'}
Plugins pytest plugins {'metadata': '1.6.0'}
======== =============== ===================================

Additional metadata

You can provide your own metadata (key, value pair) by specifying ``--metadata`` on the commandline::

pytest --metadata foo bar

Note: You can provide multiple sets of ``--metadata``::

pytest --metadata foo bar --metadata baz zoo

Continuous integration

When run in a continuous integration environment, additional metadata is added
from environment variables. Below is a list of the supported continuous
integration providers, along with links to the environment variables that are
added to metadata if they're present.

* `AppVeyor <>`_
* `Bitbucket <>`_
* `CircleCI <>`_
* `GitLab CI <>`_
* `Jenkins <>`_
* `TaskCluster <>`_
* `Travis CI <>`_

Note that if you're using `Tox <>`_ to run your tests
then you will need to `pass down any additional environment variables <>`_
for these to be picked up.

Viewing metadata

If you pass ``--verbose`` on the command line when running your tests, then the
metadata will be displayed in the terminal report header::

pytest --verbose
============================ test session starts ============================
platform darwin -- Python 3.6.4, pytest-3.4.1, py-1.5.2, pluggy-0.6.0 -- /usr/bin/python
cachedir: .pytest_cache
metadata: {'Python': '3.6.4', 'Platform': 'Darwin-17.4.0-x86_64-i386-64bit', 'Packages': {'pytest': '3.4.1', 'py': '1.5.2', 'pluggy': '0.6.0'}, 'Plugins': {'metadata': '1.6.0'}}
plugins: metadata-1.6.0

Accessing metadata

To add/modify/delete metadata at the end of metadata collection, you can use the ``pytest_metadata`` hook:

.. code-block:: python

import pytest
def pytest_metadata(metadata):
metadata.pop("password", None)

To access the metadata from a test or fixture, you can use the ``metadata``

.. code-block:: python

def test_metadata(metadata):
assert 'metadata' in metadata['Plugins']

To access the metadata from a plugin, you can use the ``_metadata`` attribute of
the ``config`` object. This can be used to read/add/modify the metadata:

.. code-block:: python

def pytest_configure(config):
if hasattr(config, '_metadata'):
config._metadata['foo'] = 'bar'

Plugin integrations

Here's a handy list of plugins that either read or contribute to the metadata:

* `pytest-base-url <>`_ - Adds the
base URL to the metadata.
* `pytest-html <>`_ - Displays the
metadata at the start of each report.
* `pytest-selenium <>`_ - Adds the
driver, capabilities, and remote server to the metadata.


- `Release Notes <>`_
- `Issue Tracker <>`_
- `Code <>`_

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
pytest_metadata-1.8.0-py2.py3-none-any.whl (9.5 kB) Copy SHA256 hash SHA256 Wheel py2.py3
pytest-metadata-1.8.0.tar.gz (9.2 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page