pytest-metadata


Namepytest-metadata JSON
Version 3.1.1 PyPI version JSON
download
home_page
Summarypytest plugin for test session metadata
upload_time2024-02-12 19:38:44
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords metadata pytest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pytest-metadata
===============

pytest-metadata is a plugin for `pytest <http://pytest.org>`_ 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 <https://github.com/pytest-dev/pytest-metadata/blob/master/development.rst>`_

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 <https://www.appveyor.com/docs/environment-variables/>`_
* `Bitbucket <https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html>`_
* `CircleCI <https://circleci.com/docs/1.0/environment-variables/>`_
* `GitLab CI <http://docs.gitlab.com/ce/ci/variables/README.html>`_
* `Jenkins <https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-JenkinsSetEnvironmentVariables>`_
* `TaskCluster <https://docs.taskcluster.net/reference/workers/docker-worker/environment>`_
* `Travis CI <https://docs.travis-ci.com/user/environment-variables/>`_

Note that if you're using `Tox <http://tox.readthedocs.io/>`_ to run your tests
then you will need to `pass down any additional environment variables <http://tox.readthedocs.io/en/latest/example/basic.html#passing-down-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

  <?xml version="1.0" encoding="utf-8"?>
  <testsuites>
    <testsuite name="pytest" errors="0" failures="0" skipped="0" tests="1" time="0.009" timestamp="2020-11-27T06:38:44.407674" hostname="sam">
      <properties>
        <property name="Daffy" value="Duck"/>
  ...

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 <https://pypi.python.org/pypi/pytest-base-url/>`_ - Adds the
  base URL to the metadata.
* `pytest-html <https://pypi.python.org/pypi/pytest-html/>`_ - Displays the
  metadata at the start of each report.
* `pytest-reporter-html1 <https://pypi.org/project/pytest-reporter-html1/>`_ -
  Presents metadata as part of the report.
* `pytest-selenium <https://pypi.python.org/pypi/pytest-selenium/>`_ - Adds the
  driver, capabilities, and remote server to the metadata.

Resources
---------

- `Release Notes <http://github.com/davehunt/pytest-metadata/blob/master/CHANGES.rst>`_
- `Issue Tracker <http://github.com/davehunt/pytest-metadata/issues>`_
- `Code <http://github.com/davehunt/pytest-metadata/>`_

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pytest-metadata",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "metadata,pytest",
    "author": "",
    "author_email": "Dave Hunt <dhunt@mozilla.com>, Jim Brannlund <jimbrannlund@fastmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/a6/85/8c969f8bec4e559f8f2b958a15229a35495f5b4ce499f6b865eac54b878d/pytest_metadata-3.1.1.tar.gz",
    "platform": null,
    "description": "pytest-metadata\n===============\n\npytest-metadata is a plugin for `pytest <http://pytest.org>`_ that provides\naccess to test session metadata.\n\n.. image:: https://img.shields.io/badge/license-MPL%202.0-blue.svg\n   :target: https://github.com/pytest-dev/pytest-metadata/blob/master/LICENSE\n   :alt: License\n.. image:: https://img.shields.io/pypi/v/pytest-metadata.svg\n   :target: https://pypi.python.org/pypi/pytest-metadata/\n   :alt: PyPI\n.. image:: https://img.shields.io/travis/pytest-dev/pytest-metadata.svg\n   :target: https://travis-ci.org/pytest-dev/pytest-metadata/\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n   :target: https://github.com/ambv/black\n   :alt: Travis\n.. image:: https://img.shields.io/github/issues-raw/pytest-dev/pytest-metadata.svg\n   :target: https://github.com/pytest-dev/pytest-metadata/issues\n   :alt: Issues\n.. image:: https://img.shields.io/requires/github/pytest-dev/pytest-metadata.svg\n   :target: https://requires.io/github/pytest-dev/pytest-metadata/requirements/?branch=master\n   :alt: Requirements\n\nRequirements\n------------\n\nYou will need the following in order to use pytest-metadata:\n\n- Python 3.8+ or PyPy3\n\nInstallation\n------------\n\nTo install pytest-metadata:\n\n.. code-block:: bash\n\n  $ pip install pytest-metadata\n\nContributing\n------------\n\nWe welcome contributions.\n\nTo learn more, see `Development <https://github.com/pytest-dev/pytest-metadata/blob/master/development.rst>`_\n\nAvailable metadata\n------------------\n\nThe following metadata is gathered by this plugin:\n\n========  =============== ===================================\nKey       Description     Example\n========  =============== ===================================\nPython    Python version  3.6.4\nPlatform  Platform        Darwin-17.4.0-x86_64-i386-64bit\nPackages  pytest packages {'py': '1.5.2', 'pytest': '3.4.1'}\nPlugins   pytest plugins  {'metadata': '1.6.0'}\n========  =============== ===================================\n\nAdditional metadata\n-------------------\n\nYou can provide your own metadata (key, value pair) by specifying ``--metadata`` on the commandline::\n\n   pytest --metadata foo bar\n\nNote: You can provide multiple sets of ``--metadata``::\n\n   pytest --metadata foo bar --metadata baz zoo\n\nThere's also the possibility of passing in metadata as a JSON string::\n\n    pytest --metadata-from-json '{\"cat_says\": \"bring the cat nip\", \"human_says\": \"yes kitty\"}'\n\nAlternatively a JSON can be read from a given file::\n\n    pytest --metadata-from-json-file path/to/valid/file.json\n\nContinuous integration\n----------------------\n\nWhen run in a continuous integration environment, additional metadata is added\nfrom environment variables. Below is a list of the supported continuous\nintegration providers, along with links to the environment variables that are\nadded to metadata if they're present.\n\n* `AppVeyor <https://www.appveyor.com/docs/environment-variables/>`_\n* `Bitbucket <https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html>`_\n* `CircleCI <https://circleci.com/docs/1.0/environment-variables/>`_\n* `GitLab CI <http://docs.gitlab.com/ce/ci/variables/README.html>`_\n* `Jenkins <https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-JenkinsSetEnvironmentVariables>`_\n* `TaskCluster <https://docs.taskcluster.net/reference/workers/docker-worker/environment>`_\n* `Travis CI <https://docs.travis-ci.com/user/environment-variables/>`_\n\nNote that if you're using `Tox <http://tox.readthedocs.io/>`_ to run your tests\nthen you will need to `pass down any additional environment variables <http://tox.readthedocs.io/en/latest/example/basic.html#passing-down-environment-variables>`_\nfor these to be picked up.\n\nViewing metadata\n----------------\n\nIf you pass ``--verbose`` on the command line when running your tests, then the\nmetadata will be displayed in the terminal report header::\n\n  pytest --verbose\n  ============================ test session starts ============================\n  platform darwin -- Python 3.6.4, pytest-3.4.1, py-1.5.2, pluggy-0.6.0 -- /usr/bin/python\n  cachedir: .pytest_cache\n  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'}}\n  plugins: metadata-1.6.0\n\nIncluding metadata in Junit XML\n-------------------------------\n\nPytest-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.\nFor example the following test module\n\n.. code-block:: python\n\n  import pytest\n\n  pytestmark = pytest.mark.usefixtures('include_metadata_in_junit_xml')\n\n  def test():\n      pass\n\nwhen called with\n\n.. code-block:: bash\n\n  pytest --metadata Daffy Duck --junit-xml=results.xml\n\nwould produce the following XML\n\n.. code-block:: xml\n\n  <?xml version=\"1.0\" encoding=\"utf-8\"?>\n  <testsuites>\n    <testsuite name=\"pytest\" errors=\"0\" failures=\"0\" skipped=\"0\" tests=\"1\" time=\"0.009\" timestamp=\"2020-11-27T06:38:44.407674\" hostname=\"sam\">\n      <properties>\n        <property name=\"Daffy\" value=\"Duck\"/>\n  ...\n\nAccessing metadata\n------------------\n\nTo add/modify/delete metadata at the end of metadata collection, you can use the ``pytest_metadata`` hook:\n\n.. code-block:: python\n\n  import pytest\n  @pytest.hookimpl(optionalhook=True)\n  def pytest_metadata(metadata):\n      metadata.pop(\"password\", None)\n\nTo access the metadata from a test or fixture, you can use the ``metadata``\nfixture:\n\n.. code-block:: python\n\n  def test_metadata(metadata):\n      assert 'metadata' in metadata['Plugins']\n\nTo access the metadata from a plugin, you can use the ``stash`` attribute of\nthe ``config`` object. This can be used to read/add/modify the metadata:\n\n.. code-block:: python\n\n  def pytest_configure(config):\n    metadata = config.pluginmanager.getplugin(\"metadata\")\n    if metadata:\n        from pytest_metadata.plugin import metadata_key\n        config.stash[metadata_key]['foo'] = 'bar'\n\nPlugin integrations\n-------------------\n\nHere's a handy list of plugins that either read or contribute to the metadata:\n\n* `pytest-base-url <https://pypi.python.org/pypi/pytest-base-url/>`_ - Adds the\n  base URL to the metadata.\n* `pytest-html <https://pypi.python.org/pypi/pytest-html/>`_ - Displays the\n  metadata at the start of each report.\n* `pytest-reporter-html1 <https://pypi.org/project/pytest-reporter-html1/>`_ -\n  Presents metadata as part of the report.\n* `pytest-selenium <https://pypi.python.org/pypi/pytest-selenium/>`_ - Adds the\n  driver, capabilities, and remote server to the metadata.\n\nResources\n---------\n\n- `Release Notes <http://github.com/davehunt/pytest-metadata/blob/master/CHANGES.rst>`_\n- `Issue Tracker <http://github.com/davehunt/pytest-metadata/issues>`_\n- `Code <http://github.com/davehunt/pytest-metadata/>`_\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "pytest plugin for test session metadata",
    "version": "3.1.1",
    "project_urls": {
        "Homepage": "https://github.com/pytest-dev/pytest-metadata",
        "Source": "https://github.com/pytest-dev/pytest-metadata",
        "Tracker": "https://github.com/pytest-dev/pytest-metadata/issues"
    },
    "split_keywords": [
        "metadata",
        "pytest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3e437e7b2ec865caa92f67b8f0e9231a798d102724ca4c0e1f414316be1c1ef2",
                "md5": "9159247cfd9c2aa518f9e0e4eb24fd17",
                "sha256": "c8e0844db684ee1c798cfa38908d20d67d0463ecb6137c72e91f418558dd5f4b"
            },
            "downloads": -1,
            "filename": "pytest_metadata-3.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9159247cfd9c2aa518f9e0e4eb24fd17",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 11428,
            "upload_time": "2024-02-12T19:38:42",
            "upload_time_iso_8601": "2024-02-12T19:38:42.531563Z",
            "url": "https://files.pythonhosted.org/packages/3e/43/7e7b2ec865caa92f67b8f0e9231a798d102724ca4c0e1f414316be1c1ef2/pytest_metadata-3.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a6858c969f8bec4e559f8f2b958a15229a35495f5b4ce499f6b865eac54b878d",
                "md5": "059f46147560a3da65c2270fb6f52965",
                "sha256": "d2a29b0355fbc03f168aa96d41ff88b1a3b44a3b02acbe491801c98a048017c8"
            },
            "downloads": -1,
            "filename": "pytest_metadata-3.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "059f46147560a3da65c2270fb6f52965",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 9952,
            "upload_time": "2024-02-12T19:38:44",
            "upload_time_iso_8601": "2024-02-12T19:38:44.887474Z",
            "url": "https://files.pythonhosted.org/packages/a6/85/8c969f8bec4e559f8f2b958a15229a35495f5b4ce499f6b865eac54b878d/pytest_metadata-3.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-12 19:38:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pytest-dev",
    "github_project": "pytest-metadata",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-metadata"
}
        
Elapsed time: 0.20366s