pytest-metadata is a plugin for pytest that provides access to test session metadata.
Requirements
You will need the following prerequisites in order to use pytest-metadata:
Python 2.7, 3.6, PyPy, or PyPy3
Installation
To install pytest-metadata:
$ pip install pytest-metadata
Development
To contribute to pytest-metadata it helps to have Pipenv and pre-commit installed.
$ pipenv install --dev
$ pre-commit install
Running Tests
We use Tox to manage running tests against the supported Python versions.
$ 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.
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:
import pytest
@pytest.mark.optionalhook
def pytest_metadata(metadata):
metadata.pop("password", None)
To access the metadata from a test or fixture, you can use the metadata fixture:
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:
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.
Resources
Release files for pytest-metadata 1.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest-metadata-1.8.0.tar.gz | 9.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_metadata-1.8.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 18.7 kB
Release files / pytest-metadata-1.8.0.tar.gz
| Download URL | pytest-metadata-1.8.0.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2071a59285de40d7541fde1eb9f1ddea1c9db165882df82781367471238b66ba
|
|
BLAKE2b-256 checksum How to use checksums |
1238eed3a1e00c765e4da61e4e833de41c3458cef5d18e819d09f0f160682993
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
|
Release files / pytest_metadata-1.8.0-py2.py3-none-any.whl
| Download URL | pytest_metadata-1.8.0-py2.py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
c29a1fb470424926c63154c1b632c02585f2ba4282932058a71d35295ff8c96d
|
|
BLAKE2b-256 checksum How to use checksums |
ce8fd0542e1aa0e23d902ce6acce2790736473da94453a36bdc7829f25734199
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
|