nonpython.rst

Overview

The [nonpython.rst](/projects/286/67218) file serves as documentation for working with non-Python test specifications within a pytest environment, specifically focusing on YAML-formatted test files. It explains how to write, collect, and execute tests defined in YAML files using pytest, through an example `conftest.py` configuration extracted from the `pytest-yamlwsgi` plugin.

This file guides users on how to extend pytest’s testing capabilities beyond Python code, enabling domain-specific testing languages or custom test formats. It highlights mechanisms for test collection, execution, failure reporting, and verbose output formatting for YAML test files.

Key functionalities documented include:

The file does not contain executable code itself but includes references and embedded code snippets illustrating usage and configuration.


Detailed Explanations

YAML Test Files in pytest

Pytest typically runs tests implemented as Python code. However, this documentation explains how to leverage YAML files as test specifications, allowing tests to be described declaratively.

**Example YAML test file snippet:**

sub1: sub1
hello: !fail
  some: other

This file might define two test cases, `sub1` which passes, and `hello` which fails with some custom failure data.

conftest.py for YAML Test Collection and Execution

The documentation references a `conftest.py` file (from the `pytest-yamlwsgi` plugin) which:

This `conftest.py` is responsible for integrating YAML tests into the pytest workflow.

**Usage Example:**

pytest test_simple.yaml

Expected output shows pytest collecting two tests from the YAML file and executing them, reporting pass/fail status accordingly.

Test Failure Representation

Pytest Command-Line Options and Output


Implementation Details


Interactions with Other System Components


Visual Diagram

The following Mermaid class diagram captures the conceptual structure of the pytest collection and execution model as extended for YAML tests, highlighting key components and their relationships within this context.

classDiagram
    class Pytest {
        +collect_tests()
        +run_tests()
        +report_results()
    }
    class Conftest_py {
        +collect_yaml_files()
        +parse_yaml()
        +create_yaml_test_items()
        +repr_failure(excinfo)
        +reportinfo()
    }
    class YamlFile {
        +filepath: str
        +load_contents()
    }
    class YamlTestItem {
        +name: str
        +run()
        +report_failure()
    }
    class PyYAMLParser {
        +load(file)
    }

    Pytest --> Conftest_py : uses
    Conftest_py --> YamlFile : collects
    YamlFile --> PyYAMLParser : parses
    Conftest_py --> YamlTestItem : creates
    YamlTestItem --> Pytest : reports to

Summary

This documentation file [nonpython.rst](/projects/286/67218) provides a focused explanation and usage guide for running non-Python tests in pytest using YAML files. It outlines the necessary configuration, execution model, and reporting mechanisms to enable YAML as a test definition format. This approach empowers test authors to write tests declaratively and extend pytest’s capabilities to custom testing domains.

By following this guide and using the referenced `conftest.py` approach, users can integrate YAML-based tests seamlessly into pytest workflows, benefiting from pytest’s rich features such as test discovery, detailed reporting, and flexible failure presentation.