### Setup Development Environment with Hatch and pre-commit Source: https://github.com/pytest-dev/pytest-metadata/blob/master/development.rst This command sets up the Python virtual environment using Hatch and installs pre-commit hooks for code styling and formatting, ensuring consistent contributions. ```bash $ hatch -e test run pre-commit install ``` -------------------------------- ### Install pre-commit Manually Source: https://github.com/pytest-dev/pytest-metadata/blob/master/development.rst For users not utilizing Hatch, these commands manually install the pre-commit tool and set up its hooks in the repository, aiding in code quality enforcement. ```bash $ pip install pre-commit $ pre-commit install ``` -------------------------------- ### Install and Run Tests with Tox Manually Source: https://github.com/pytest-dev/pytest-metadata/blob/master/development.rst If not using Hatch, these commands install Tox and then run the project's tests against various Python environments, verifying compatibility and functionality. ```bash $ pip install tox $ tox ``` -------------------------------- ### Install pytest-metadata plugin Source: https://github.com/pytest-dev/pytest-metadata/blob/master/README.rst Instructions on how to install the pytest-metadata plugin using the pip package manager. ```bash $ pip install pytest-metadata ``` -------------------------------- ### Available pytest-metadata keys and descriptions Source: https://github.com/pytest-dev/pytest-metadata/blob/master/README.rst Details the standard metadata keys automatically gathered by the pytest-metadata plugin, along with their descriptions and example values. ```APIDOC Metadata Keys: - Python: Description: Python version Example: 3.6.4 - Platform: Description: Platform Example: Darwin-17.4.0-x86_64-i386-64bit - Packages: Description: pytest packages Example: {'py': '1.5.2', 'pytest': '3.4.1'} - Plugins: Description: pytest plugins Example: {'metadata': '1.6.0'} ``` -------------------------------- ### Generate Junit XML with metadata from pytest Source: https://github.com/pytest-dev/pytest-metadata/blob/master/README.rst Command-line example for running pytest to generate a Junit XML report that includes custom metadata, leveraging the `include_metadata_in_junit_xml` fixture. ```bash pytest --metadata Daffy Duck --junit-xml=results.xml ``` -------------------------------- ### Run Tests with Hatch and Tox Source: https://github.com/pytest-dev/pytest-metadata/blob/master/development.rst This command executes the project's test suite across supported Python versions using Tox, managed through the Hatch environment, ensuring comprehensive test coverage. ```bash $ hatch -e test run tox ``` -------------------------------- ### Example Junit XML output with pytest metadata Source: https://github.com/pytest-dev/pytest-metadata/blob/master/README.rst Illustrative snippet of a Junit XML report showing how metadata is included as `` tags within the `` element. ```xml ``` -------------------------------- ### Access Pytest Metadata from Test or Fixture Source: https://github.com/pytest-dev/pytest-metadata/blob/master/README.rst Illustrates how to retrieve metadata within a pytest test function or fixture by injecting the `metadata` fixture. The example asserts the presence of 'metadata' within the 'Plugins' section of the collected data. ```Python def test_metadata(metadata): assert 'metadata' in metadata['Plugins'] ``` -------------------------------- ### Modify Pytest Metadata using pytest_metadata Hook Source: https://github.com/pytest-dev/pytest-metadata/blob/master/README.rst Demonstrates how to use the `pytest_metadata` hook to add, modify, or delete metadata entries after collection. This example specifically shows how to remove a 'password' entry from the collected metadata. ```Python import pytest @pytest.hookimpl(optionalhook=True) def pytest_metadata(metadata): metadata.pop("password", None) ``` -------------------------------- ### Add custom metadata to pytest via command line Source: https://github.com/pytest-dev/pytest-metadata/blob/master/README.rst Demonstrates how to provide custom key-value metadata pairs to pytest using the `--metadata` command-line option. Multiple pairs can be specified by repeating the option. ```bash pytest --metadata foo bar pytest --metadata foo bar --metadata baz zoo ``` -------------------------------- ### Add custom metadata to pytest from a JSON file Source: https://github.com/pytest-dev/pytest-metadata/blob/master/README.rst Illustrates how to load metadata into pytest from a specified JSON file using the `--metadata-from-json-file` command-line option. ```bash pytest --metadata-from-json-file path/to/valid/file.json ``` -------------------------------- ### View pytest metadata in terminal report Source: https://github.com/pytest-dev/pytest-metadata/blob/master/README.rst Explains how to display the gathered metadata in the terminal report header by running pytest with the `--verbose` flag. ```bash pytest --verbose ``` -------------------------------- ### Add custom metadata to pytest from a JSON string Source: https://github.com/pytest-dev/pytest-metadata/blob/master/README.rst Shows how to pass metadata to pytest as a JSON string using the `--metadata-from-json` command-line option. ```bash pytest --metadata-from-json '{"cat_says": "bring the cat nip", "human_says": "yes kitty"}' ``` -------------------------------- ### Include pytest metadata in Junit XML report Source: https://github.com/pytest-dev/pytest-metadata/blob/master/README.rst Demonstrates how to use the `include_metadata_in_junit_xml` fixture in a Python test module to embed session metadata as properties in the generated Junit XML report. ```python import pytest pytestmark = pytest.mark.usefixtures('include_metadata_in_junit_xml') def test(): pass ``` -------------------------------- ### Access and Modify Pytest Metadata from a Plugin Source: https://github.com/pytest-dev/pytest-metadata/blob/master/README.rst Shows how a pytest plugin can access and modify metadata using the `config.stash` attribute within the `pytest_configure` hook. It demonstrates adding a new 'foo' entry with value 'bar' to the metadata dictionary. ```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' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.