pytest_metadata-3.1.1/.pre-commit-config.yaml0000644000000000000000000000070014562471507016123 0ustar00repos: - repo: https://github.com/psf/black rev: 24.1.1 hooks: - id: black args: [--safe, --quiet] language_version: python3 - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - repo: https://github.com/PyCQA/flake8 rev: 7.0.0 hooks: - id: flake8 exclude: docs language_version: python3 pytest_metadata-3.1.1/CHANGES.rst0000644000000000000000000000656514562471507013463 0ustar00Release Notes ------------- 3.1.1 (2024-02-08) ------------------ * Add environment variables for AWS CodeBuild CI. * Thanks to `@dougch `_ for the PR. 3.1.0 (2024-02-01) ------------------ * Support Pytest 8.0 3.0.0 (2023-05-27) ------------------ * Group CLI options * Thanks to `@xmuskrat `_ for reporting. * Switch to Hatch * Use `pytest.stash` internally instead of `_metadata` * Simplify code * Thanks to `@LieYangGH `_ for the PR. 2.0.4 (2022-10-30) ------------------ * Fix deprecated `pytest.mark.optionalhook` marker. 2.0.3 (2022-10-26) ------------------ * Remove `py` dependency * Thanks to `@Czaki `_ for reporting. 2.0.2 (2022-07-15) ------------------ * Allow all python versions above 3.7 2.0.1 (2022-03-26) ------------------ * Fix issues with switching to pyproject.toml * Thanks to `@dvzrv `_ and `@eltrufas `_ for raising issues and providing fixes. 2.0.0 (2022-03-22) ------------------ * Drop support for python 2.7 and 3.6 * Add support for python 3.9 and 3.10 * Introduce pyproject.toml * Provide metadata via JSON file * Thanks to `@digitalorder `_ for the PR 1.11.0 (2020-11-72) ------------------- * Provide a session fixture to include metadata in Junit XMLs as property tags. * Thanks to `@sanga `_ for the PR 1.10.0 (2020-06-24) ------------------ * Compatible with ``pytest-xdist`` 1.22.3+, now including 2.0+ * Thanks to `@Zac-HD `_ for the PR 1.9.0 (2020-04-03) ------------------ * Add ``--metadata-from-json`` argument to support passing metadata as json. * Thanks to `@ImXron `_ for the PR * Add support for python 3.8. * Thanks to `@hugovk `_ for the PR * Remove always-masked GitLab environment variables. * Thanks to `@borntyping `_ for the PR 1.8.0 (2019-01-03) ------------------ * Add environment variables for Bitbucket pipelines (CI). 1.7.0 (2018-04-05) ------------------ * Add hook for modifying metadata. * Thanks to `@j19sch `_ for the PR 1.6.0 (2018-02-21) ------------------ * Only show metadata in console when ``--verbose`` is specified. 1.5.1 (2017-11-28) ------------------ * Support latest versions of pytest, which no longer vendor pluggy. 1.5.0 (2017-05-15) ------------------ * Add environment variables for GitLab CI. * Thanks to `@tinproject `_ for the PR 1.4.0 (2017-05-04) ------------------ * Allow additional metadata to be specified on the command-line. * Thanks to `@BeyondEvil `_ for the PR 1.3.0 (2017-03-01) ------------------ * Display initial metadata in report header. * Update metadata when running with xdist processes instead of overwriting. 1.2.0 (2017-02-24) ------------------ * Added environment variables for AppVeyor and CircleCI. * Try to run ``pytest_configure`` first so that other plugins can contribute to the metadata. 1.1.0 (2017-02-16) ------------------ * Moved pytest related packages into 'Packages' as a dictionary. * Changed installed plugins from a list to a dictionary. 1.0.0 (2017-02-16) ------------------ * Initial release pytest_metadata-3.1.1/development.rst0000644000000000000000000000333514562471507014725 0ustar00Development =========== To contribute to `pytest-metadata` you can use `Hatch `_ to manage a python virtual environment and `pre-commit `_ to help you with styling and formatting. To setup the virtual environment and pre-commit, run: .. code-block:: bash $ hatch -e test run pre-commit install If you're not using ``Hatch``, to install ``pre-commit``, run: .. code-block:: bash $ pip install pre-commit $ pre-commit install Automated Testing ----------------- All pull requests and merges are tested in `GitHub Actions `_ based on the workflows defined in ``.github/workflows``. Running Tests ------------- You will need `Tox `_ installed to run the tests against the supported Python versions. If you're using ``Hatch`` it will be installed for you. With ``Hatch``, run: .. code-block:: bash $ hatch -e test run tox Otherwise, to install and run, do: .. code-block:: bash $ pip install tox $ tox Releasing a new version ----------------------- Follow these steps to release a new version of the project: #. Update your local master with the upstream master (``git pull --rebase upstream master``) #. Create a new branch and update ``CHANGES.rst`` with the new version, today's date, and all changes/new features #. Update ``pyproject.toml`` with the new version #. Commit and push the new branch and then create a new pull request #. Wait for tests and reviews and then merge the branch #. Once merged, update your local master again (``git pull --rebase upstream master``) #. Tag the release with the new release version (``git tag ``) #. Push the tag (``git push upstream --tags``) #. Done. pytest_metadata-3.1.1/tox.ini0000644000000000000000000000124614562471507013163 0ustar00[tox] envlist = py{3.8, 3.9, 3.10, 3.11, 3.12, py3.10}, linting isolated_build = True [testenv] setenv = PYTHONDONTWRITEBYTECODE=1 commands = pytest -s -ra --color=yes {posargs} [testenv:linting] skip_install = True basepython = python3 deps = pre-commit commands = pre-commit run --all-files --show-diff-on-failure [testenv:devel] description = Tests with unreleased deps basepython = python3 pip_pre = True deps = pytest @ git+https://github.com/pytest-dev/pytest.git [flake8] max-line-length = 120 exclude = .eggs,.tox # rationale here: # https://github.com/psf/black/blob/master/docs/the_black_code_style.md#slices extend-ignore = E203 [pytest] testpaths = tests pytest_metadata-3.1.1/src/pytest_metadata/__init__.py0000644000000000000000000000000014562471507017723 0ustar00pytest_metadata-3.1.1/src/pytest_metadata/__version.py0000644000000000000000000000063314562471507020163 0ustar00# file generated by setuptools_scm # don't change, don't track in version control TYPE_CHECKING = False if TYPE_CHECKING: from typing import Tuple, Union VERSION_TUPLE = Tuple[Union[int, str], ...] else: VERSION_TUPLE = object version: str __version__: str __version_tuple__: VERSION_TUPLE version_tuple: VERSION_TUPLE __version__ = version = '3.1.1' __version_tuple__ = version_tuple = (3, 1, 1) pytest_metadata-3.1.1/src/pytest_metadata/hooks.py0000644000000000000000000000043314562471507017321 0ustar00# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. def pytest_metadata(metadata, config): """Called after collecting metadata""" pytest_metadata-3.1.1/src/pytest_metadata/plugin.py0000644000000000000000000000747514562471507017511 0ustar00# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. import json import os import platform try: import _pytest._pluggy as pluggy except ImportError: import pluggy import pytest from pytest_metadata.ci import ( appveyor, bitbucket, circleci, codebuild, gitlab_ci, jenkins, taskcluster, travis_ci, ) CONTINUOUS_INTEGRATION = [ appveyor.ENVIRONMENT_VARIABLES, bitbucket.ENVIRONMENT_VARIABLES, circleci.ENVIRONMENT_VARIABLES, codebuild.ENVIRONMENT_VARIABLES, gitlab_ci.ENVIRONMENT_VARIABLES, jenkins.ENVIRONMENT_VARIABLES, taskcluster.ENVIRONMENT_VARIABLES, travis_ci.ENVIRONMENT_VARIABLES, ] metadata_key = pytest.StashKey[dict]() def pytest_addhooks(pluginmanager): from pytest_metadata import hooks pluginmanager.add_hookspecs(hooks) @pytest.fixture(scope="session") def metadata(pytestconfig): """Provide test session metadata""" return pytestconfig.stash[metadata_key] @pytest.fixture(scope="session") def include_metadata_in_junit_xml(metadata, pytestconfig, record_testsuite_property): """Provide test session metadata""" metadata_ = pytestconfig.stash[metadata_key] for name, value in metadata_.items(): record_testsuite_property(name, value) def pytest_addoption(parser): group = parser.getgroup("pytest-metadata") group.addoption( "--metadata", action="append", default=[], dest="metadata", metavar=("key", "value"), nargs=2, help="additional metadata.", ) group.addoption( "--metadata-from-json", action="store", default="{}", dest="metadata_from_json", help="additional metadata from a json string.", ) group.addoption( "--metadata-from-json-file", type=str, dest="metadata_from_json_file", help="additional metadata from a json file.", ) @pytest.hookimpl(tryfirst=True) def pytest_configure(config): config.stash[metadata_key] = { "Python": platform.python_version(), "Platform": platform.platform(), "Packages": { "pytest": pytest.__version__, "pluggy": pluggy.__version__, }, } config.stash[metadata_key].update({k: v for k, v in config.getoption("metadata")}) config.stash[metadata_key].update( json.loads(config.getoption("metadata_from_json")) ) if config.getoption("metadata_from_json_file"): with open(config.getoption("metadata_from_json_file"), "r") as json_file: config.stash[metadata_key].update(json.load(json_file)) plugins = dict() for plugin, dist in config.pluginmanager.list_plugin_distinfo(): name, version = dist.project_name, dist.version if name.startswith("pytest-"): name = name[7:] plugins[name] = version config.stash[metadata_key]["Plugins"] = plugins for provider in CONTINUOUS_INTEGRATION: for var in provider: if os.environ.get(var): config.stash[metadata_key].update({var: os.environ.get(var)}) if hasattr(config, "workeroutput"): config.workeroutput["metadata"] = config.stash[metadata_key] config.hook.pytest_metadata(metadata=config.stash[metadata_key], config=config) def pytest_report_header(config): if config.getoption("verbose") > 0: return "metadata: {0}".format(config.stash[metadata_key]) @pytest.hookimpl(optionalhook=True) def pytest_testnodedown(node): # note that any metadata from remote workers will be replaced with the # environment from the final worker to quit if hasattr(node, "workeroutput"): node.config.stash[metadata_key].update(node.workeroutput["metadata"]) pytest_metadata-3.1.1/src/pytest_metadata/ci/__init__.py0000644000000000000000000000000014562471507020316 0ustar00pytest_metadata-3.1.1/src/pytest_metadata/ci/appveyor.py0000644000000000000000000000212414562471507020435 0ustar00# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. ENVIRONMENT_VARIABLES = [ "APPVEYOR_API_URL", "APPVEYOR_ACCOUNT_NAME", "APPVEYOR_PROJECT_ID", "APPVEYOR_PROJECT_NAME", "APPVEYOR_PROJECT_SLUG", "APPVEYOR_BUILD_FOLDER", "APPVEYOR_BUILD_ID", "APPVEYOR_BUILD_NUMBER", "APPVEYOR_BUILD_VERSION", "APPVEYOR_PULL_REQUEST_NUMBER", "APPVEYOR_PULL_REQUEST_TITLE", "APPVEYOR_JOB_ID", "APPVEYOR_JOB_NAME", "APPVEYOR_REPO_PROVIDER", "APPVEYOR_REPO_SCM", "APPVEYOR_REPO_NAME", "APPVEYOR_REPO_BRANCH", "APPVEYOR_REPO_TAG", "APPVEYOR_REPO_TAG_NAME", "APPVEYOR_REPO_COMMIT", "APPVEYOR_REPO_COMMIT_AUTHOR", "APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL", "APPVEYOR_REPO_COMMIT_TIMESTAMP", "APPVEYOR_REPO_COMMIT_MESSAGE", "APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED", "APPVEYOR_SCHEDULED_BUILD", "APPVEYOR_FORCED_BUILD", "APPVEYOR_RE_BUILD", "PLATFORM", "CONFIGURATION", ] pytest_metadata-3.1.1/src/pytest_metadata/ci/bitbucket.py0000644000000000000000000000107514562471507020550 0ustar00# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. ENVIRONMENT_VARIABLES = [ "CI", "BITBUCKET_BUILD_NUMBER", "BITBUCKET_CLONE_DIR", "BITBUCKET_COMMIT", "BITBUCKET_REPO_OWNER", "BITBUCKET_REPO_OWNER_UUID", "BITBUCKET_REPO_SLUG", "BITBUCKET_REPO_UUID", "BITBUCKET_BRANCH", "BITBUCKET_TAG", "BITBUCKET_BOOKMARK", "BITBUCKET_PARALLEL_STEP", "BITBUCKET_PARALLEL_STEP_COUNT", ] pytest_metadata-3.1.1/src/pytest_metadata/ci/circleci.py0000644000000000000000000000136514562471507020353 0ustar00# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. ENVIRONMENT_VARIABLES = [ "CIRCLE_PROJECT_USERNAME", "CIRCLE_PROJECT_REPONAME", "CIRCLE_BRANCH", "CIRCLE_TAG", "CIRCLE_SHA1", "CIRCLE_REPOSITORY_URL", "CIRCLE_COMPARE_URL", "CIRCLE_BUILD_URL", "CIRCLE_BUILD_NUM", "CIRCLE_PREVIOUS_BUILD_NUM", "CI_PULL_REQUESTS", "CI_PULL_REQUEST", "CIRCLE_ARTIFACTS", "CIRCLE_USERNAME", "CIRCLE_TEST_REPORTS", "CIRCLE_PR_USERNAME", "CIRCLE_PR_REPONAME", "CIRCLE_PR_NUMBER", "CIRCLE_NODE_TOTAL", "CIRCLE_NODE_INDEX", "CIRCLE_BUILD_IMAGE", ] pytest_metadata-3.1.1/src/pytest_metadata/ci/codebuild.py0000644000000000000000000000076714562471507020535 0ustar00# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # Based on https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html ENVIRONMENT_VARIABLES = [ "AWS_REGION", "CODEBUILD_BUILD_ID", "CODEBUILD_BUILD_NUMBER", "CODEBUILD_RESOLVED_SOURCE_VERSION", "CODEBUILD_SOURCE_REPO_URL", "CODEBUILD_SOURCE_VERSION", ] pytest_metadata-3.1.1/src/pytest_metadata/ci/gitlab_ci.py0000644000000000000000000000204414562471507020506 0ustar00# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. ENVIRONMENT_VARIABLES = [ "CI", "CI_COMMIT_REF_NAME", "CI_COMMIT_REF_SLUG", "CI_COMMIT_SHA", "CI_COMMIT_TAG", "CI_DEBUG_TRACE", "CI_ENVIRONMENT_NAME", "CI_ENVIRONMENT_SLUG", "CI_JOB_ID", "CI_JOB_MANUAL", "CI_JOB_NAME", "CI_JOB_STAGE", "CI_RUNNER_DESCRIPTION", "CI_RUNNER_ID", "CI_RUNNER_TAGS", "CI_PIPELINE_ID", "CI_PIPELINE_TRIGGERED", "CI_PROJECT_DIR", "CI_PROJECT_ID", "CI_PROJECT_NAME", "CI_PROJECT_NAMESPACE", "CI_PROJECT_PATH", "CI_PROJECT_URL", "CI_REGISTRY", "CI_REGISTRY_IMAGE", "CI_REGISTRY_USER", "CI_SERVER", "CI_SERVER_NAME", "CI_SERVER_REVISION", "CI_SERVER_VERSION", "ARTIFACT_DOWNLOAD_ATTEMPTS", "GET_SOURCES_ATTEMPTS", "GITLAB_CI", "GITLAB_USER_ID", "GITLAB_USER_EMAIL", "RESTORE_CACHE_ATTEMPTS", ] pytest_metadata-3.1.1/src/pytest_metadata/ci/jenkins.py0000644000000000000000000000076014562471507020235 0ustar00# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. ENVIRONMENT_VARIABLES = [ "BUILD_NUMBER", "BUILD_ID", "BUILD_URL", "NODE_NAME", "JOB_NAME", "BUILD_TAG", "EXECUTOR_NUMBER", "JENKINS_URL", "JAVA_HOME", "WORKSPACE", "SVN_REVISION", "CVS_BRANCH", "GIT_COMMIT", "GIT_URL", "GIT_BRANCH", ] pytest_metadata-3.1.1/src/pytest_metadata/ci/taskcluster.py0000644000000000000000000000036614562471507021142 0ustar00# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. ENVIRONMENT_VARIABLES = ["TASK_ID", "RUN_ID"] pytest_metadata-3.1.1/src/pytest_metadata/ci/travis_ci.py0000644000000000000000000000121614562471507020554 0ustar00# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. ENVIRONMENT_VARIABLES = [ "TRAVIS_BRANCH", "TRAVIS_BUILD_ID", "TRAVIS_BUILD_NUMBER", "TRAVIS_COMMIT", "TRAVIS_COMMIT_MESSAGE", "TRAVIS_COMMIT_RANGE", "TRAVIS_EVENT_TYPE", "TRAVIS_JOB_ID", "TRAVIS_JOB_NUMBER", "TRAVIS_OS_NAME", "TRAVIS_PULL_REQUEST", "TRAVIS_PULL_REQUEST_BRANCH", "TRAVIS_PULL_REQUEST_SHA", "TRAVIS_PULL_REQUEST_SLUG", "TRAVIS_REPO_SLUG", "TRAVIS_SUDO", "TRAVIS_TAG", ] pytest_metadata-3.1.1/tests/__init__.py0000644000000000000000000000000014562471507015106 0ustar00pytest_metadata-3.1.1/tests/test_metadata.py0000644000000000000000000001016614562471507016204 0ustar00# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. import pytest from xml.etree import ElementTree as ET pytest_plugins = ("pytester",) def test_metadata(pytester): pytester.makepyfile( """ def test_pass(metadata): for k in ['Python', 'Platform', 'Packages']: assert k in metadata assert 'JENKINS_URL' not in metadata """ ) result = pytester.runpytest() assert result.ret == 0 def test_environment_variables(pytester, monkeypatch): monkeypatch.setenv("JENKINS_URL", "foo") monkeypatch.setenv("GIT_COMMIT", "bar") pytester.makepyfile( """ def test_pass(metadata): assert metadata.get('JENKINS_URL') == 'foo' assert metadata.get('GIT_COMMIT') == 'bar' """ ) result = pytester.runpytest() assert result.ret == 0 def test_additional_metadata(pytester): pytester.makepyfile( """ def test_pass(metadata): assert metadata.get('Dave') == 'Hunt' assert metadata.get('Jim') == 'Bob' """ ) result = pytester.runpytest( "--metadata", "Dave", "Hunt", "--metadata", "Jim", "Bob" ) assert result.ret == 0 @pytest.mark.parametrize("junit_format", ["xunit1", "xunit2"]) def test_junit_integration(pytester, junit_format): pytester.makepyfile( """ import pytest pytestmark = pytest.mark.usefixtures('include_metadata_in_junit_xml') def test_pass(): pass """ ) result = pytester.runpytest( "--metadata", "Daffy", "Duck", "--junit-xml=results.xml", "--override-ini='junit_family={}'".format(junit_format), ) assert result.ret == 0 results_file = pytester.path.joinpath("results.xml") assert results_file.exists() with results_file.open() as fd: xml = ET.parse(fd) properties = xml.findall(".//property") xml_metadata = [p.attrib for p in properties] # value passed on the cmdline appears assert {"name": "Daffy", "value": "Duck"} in xml_metadata def test_additional_metadata_from_json(pytester): pytester.makepyfile( """ def test_pass(metadata): assert metadata.get('Imran') == 'Mumtaz' """ ) result = pytester.runpytest("--metadata-from-json", '{"Imran": "Mumtaz"}') assert result.ret == 0 def test_additional_metadata_from_json_file(pytester): pytester.makepyfile( """ def test_pass(metadata): assert metadata.get('John') == 'Cena' """ ) pytester.makefile(".json", temp='{"John": "Cena"}') result = pytester.runpytest("--metadata-from-json-file", "temp.json") assert result.ret == 0 def test_additional_metadata_using_key_values_json_str_and_file(pytester): pytester.makepyfile( """ def test_pass(metadata): assert metadata.get('John') == 'Cena' assert metadata.get('Dwayne') == 'Johnson' assert metadata.get('Andre') == 'The Giant' """ ) pytester.makefile(".json", temp='{"Andre": "The Giant"}') result = pytester.runpytest( "--metadata", "John", "Cena", "--metadata-from-json", '{"Dwayne": "Johnson"}', "--metadata-from-json-file", "temp.json", ) assert result.ret == 0 def test_metadata_hook(pytester): pytester.makeconftest( """ import pytest @pytest.hookimpl(optionalhook=True) def pytest_metadata(metadata): metadata['Dave'] = 'Hunt' """ ) pytester.makepyfile( """ def test_pass(metadata): assert metadata.get('Dave') == 'Hunt' """ ) result = pytester.runpytest() assert result.ret == 0 def test_report_header(pytester): result = pytester.runpytest() assert not any(line.startswith("metadata:") for line in result.stdout.lines) result = pytester.runpytest("-v") assert any(line.startswith("metadata:") for line in result.stdout.lines) pytest_metadata-3.1.1/.gitignore0000644000000000000000000000011114562471507013626 0ustar00__pycache__ __version.py *.egg-info/ *.pyc .cache .eggs .tox build dist pytest_metadata-3.1.1/AUTHORS0000644000000000000000000000017014562471507012713 0ustar00Agustín Herranz Arminius (numirias) Dave Hunt Imran Mumtaz Jim Brännlund Sam Clements Tomas Krizek Zac Hatfield-Dodds pytest_metadata-3.1.1/LICENSE0000644000000000000000000000030114562471507012644 0ustar00This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. pytest_metadata-3.1.1/README.rst0000644000000000000000000001532614562471507013343 0ustar00pytest-metadata =============== pytest-metadata is a plugin for `pytest `_ that provides access to test session metadata. .. image:: https://img.shields.io/badge/license-MPL%202.0-blue.svg :target: https://github.com/pytest-dev/pytest-metadata/blob/master/LICENSE :alt: License .. image:: https://img.shields.io/pypi/v/pytest-metadata.svg :target: https://pypi.python.org/pypi/pytest-metadata/ :alt: PyPI .. image:: https://img.shields.io/travis/pytest-dev/pytest-metadata.svg :target: https://travis-ci.org/pytest-dev/pytest-metadata/ .. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/ambv/black :alt: Travis .. image:: https://img.shields.io/github/issues-raw/pytest-dev/pytest-metadata.svg :target: https://github.com/pytest-dev/pytest-metadata/issues :alt: Issues .. image:: https://img.shields.io/requires/github/pytest-dev/pytest-metadata.svg :target: https://requires.io/github/pytest-dev/pytest-metadata/requirements/?branch=master :alt: Requirements Requirements ------------ You will need the following in order to use pytest-metadata: - Python 3.8+ or PyPy3 Installation ------------ To install pytest-metadata: .. code-block:: bash $ pip install pytest-metadata Contributing ------------ We welcome contributions. To learn more, see `Development `_ 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 There's also the possibility of passing in metadata as a JSON string:: pytest --metadata-from-json '{"cat_says": "bring the cat nip", "human_says": "yes kitty"}' Alternatively a JSON can be read from a given file:: pytest --metadata-from-json-file path/to/valid/file.json 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 Including metadata in Junit XML ------------------------------- Pytest-metadata provides the session scoped fixture :code:`include_metadata_in_junit_xml` that you may use to include any metadata in Junit XML as ``property`` tags. For example the following test module .. code-block:: python import pytest pytestmark = pytest.mark.usefixtures('include_metadata_in_junit_xml') def test(): pass when called with .. code-block:: bash pytest --metadata Daffy Duck --junit-xml=results.xml would produce the following XML .. code-block:: xml ... 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 @pytest.hookimpl(optionalhook=True) def pytest_metadata(metadata): metadata.pop("password", None) To access the metadata from a test or fixture, you can use the ``metadata`` fixture: .. code-block:: python def test_metadata(metadata): assert 'metadata' in metadata['Plugins'] To access the metadata from a plugin, you can use the ``stash`` attribute of the ``config`` object. This can be used to read/add/modify the metadata: .. code-block:: python def pytest_configure(config): metadata = config.pluginmanager.getplugin("metadata") if metadata: from pytest_metadata.plugin import metadata_key config.stash[metadata_key]['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-reporter-html1 `_ - Presents metadata as part of the report. * `pytest-selenium `_ - Adds the driver, capabilities, and remote server to the metadata. Resources --------- - `Release Notes `_ - `Issue Tracker `_ - `Code `_ pytest_metadata-3.1.1/pyproject.toml0000644000000000000000000000363614562471507014571 0ustar00[build-system] build-backend = "hatchling.build" requires = [ "hatch-vcs>=0.3", "hatchling>=1.13", ] [project] name = "pytest-metadata" description = "pytest plugin for test session metadata" readme = "README.rst" license = "MPL-2.0" requires-python = ">=3.8" keywords = [ "pytest", "metadata", ] authors = [ { name = "Dave Hunt", email = "dhunt@mozilla.com" }, { name = "Jim Brannlund", email = "jimbrannlund@fastmail.com" }, ] classifiers = [ "Development Status :: 5 - Production/Stable", "Framework :: Pytest", "Intended Audience :: Developers", "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", "Natural Language :: English", "Operating System :: POSIX", "Operating System :: Microsoft :: Windows", "Operating System :: MacOS :: MacOS X", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Quality Assurance", "Topic :: Software Development :: Testing", "Topic :: Utilities", ] dependencies = [ "pytest>=7.0.0", ] dynamic = [ "version", ] [project.optional-dependencies] test = [ "black>=22.1.0", "flake8>=4.0.1", "pre-commit>=2.17.0", "tox>=3.24.5", ] [project.urls] Homepage = "https://github.com/pytest-dev/pytest-metadata" Tracker = "https://github.com/pytest-dev/pytest-metadata/issues" Source = "https://github.com/pytest-dev/pytest-metadata" [project.entry-points.pytest11] metadata = 'pytest_metadata.plugin' [tool.hatch.envs.test] features = [ "test", ] [tool.hatch.version] source = "vcs" [tool.hatch.build.targets.sdist] exclude = [ "/.github", ] [tool.hatch.build.hooks.vcs] version-file = "src/pytest_metadata/__version.py" pytest_metadata-3.1.1/PKG-INFO0000644000000000000000000002063114562471507012744 0ustar00Metadata-Version: 2.1 Name: pytest-metadata Version: 3.1.1 Summary: pytest plugin for test session metadata Project-URL: Homepage, https://github.com/pytest-dev/pytest-metadata Project-URL: Tracker, https://github.com/pytest-dev/pytest-metadata/issues Project-URL: Source, https://github.com/pytest-dev/pytest-metadata Author-email: Dave Hunt , Jim Brannlund License-Expression: MPL-2.0 License-File: AUTHORS License-File: LICENSE Keywords: metadata,pytest Classifier: Development Status :: 5 - Production/Stable Classifier: Framework :: Pytest Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0) Classifier: Natural Language :: English Classifier: Operating System :: MacOS :: MacOS X Classifier: Operating System :: Microsoft :: Windows Classifier: Operating System :: POSIX Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development :: Quality Assurance Classifier: Topic :: Software Development :: Testing Classifier: Topic :: Utilities Requires-Python: >=3.8 Requires-Dist: pytest>=7.0.0 Provides-Extra: test Requires-Dist: black>=22.1.0; extra == 'test' Requires-Dist: flake8>=4.0.1; extra == 'test' Requires-Dist: pre-commit>=2.17.0; extra == 'test' Requires-Dist: tox>=3.24.5; extra == 'test' Description-Content-Type: text/x-rst pytest-metadata =============== pytest-metadata is a plugin for `pytest `_ that provides access to test session metadata. .. image:: https://img.shields.io/badge/license-MPL%202.0-blue.svg :target: https://github.com/pytest-dev/pytest-metadata/blob/master/LICENSE :alt: License .. image:: https://img.shields.io/pypi/v/pytest-metadata.svg :target: https://pypi.python.org/pypi/pytest-metadata/ :alt: PyPI .. image:: https://img.shields.io/travis/pytest-dev/pytest-metadata.svg :target: https://travis-ci.org/pytest-dev/pytest-metadata/ .. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/ambv/black :alt: Travis .. image:: https://img.shields.io/github/issues-raw/pytest-dev/pytest-metadata.svg :target: https://github.com/pytest-dev/pytest-metadata/issues :alt: Issues .. image:: https://img.shields.io/requires/github/pytest-dev/pytest-metadata.svg :target: https://requires.io/github/pytest-dev/pytest-metadata/requirements/?branch=master :alt: Requirements Requirements ------------ You will need the following in order to use pytest-metadata: - Python 3.8+ or PyPy3 Installation ------------ To install pytest-metadata: .. code-block:: bash $ pip install pytest-metadata Contributing ------------ We welcome contributions. To learn more, see `Development `_ 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 There's also the possibility of passing in metadata as a JSON string:: pytest --metadata-from-json '{"cat_says": "bring the cat nip", "human_says": "yes kitty"}' Alternatively a JSON can be read from a given file:: pytest --metadata-from-json-file path/to/valid/file.json 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 Including metadata in Junit XML ------------------------------- Pytest-metadata provides the session scoped fixture :code:`include_metadata_in_junit_xml` that you may use to include any metadata in Junit XML as ``property`` tags. For example the following test module .. code-block:: python import pytest pytestmark = pytest.mark.usefixtures('include_metadata_in_junit_xml') def test(): pass when called with .. code-block:: bash pytest --metadata Daffy Duck --junit-xml=results.xml would produce the following XML .. code-block:: xml ... 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 @pytest.hookimpl(optionalhook=True) def pytest_metadata(metadata): metadata.pop("password", None) To access the metadata from a test or fixture, you can use the ``metadata`` fixture: .. code-block:: python def test_metadata(metadata): assert 'metadata' in metadata['Plugins'] To access the metadata from a plugin, you can use the ``stash`` attribute of the ``config`` object. This can be used to read/add/modify the metadata: .. code-block:: python def pytest_configure(config): metadata = config.pluginmanager.getplugin("metadata") if metadata: from pytest_metadata.plugin import metadata_key config.stash[metadata_key]['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-reporter-html1 `_ - Presents metadata as part of the report. * `pytest-selenium `_ - Adds the driver, capabilities, and remote server to the metadata. Resources --------- - `Release Notes `_ - `Issue Tracker `_ - `Code `_