attic.rst

Overview

This file provides an instructional example of how to configure and implement acceptance tests using the pytest framework. It demonstrates defining custom command-line options, creating fixture factories (funcargs) for acceptance testing, and how to decorate these fixtures at different scopes (global `conftest.py` and per-test-module) to customize test behavior.

The primary purpose of this file is to guide users on enabling, running, and structuring acceptance tests that may be slower or more complex than typical unit tests. It illustrates how to skip tests unless a specific command line flag (`-A`) is set, how to create temporary directories for test isolation, and how to run subprocess commands as part of acceptance tests.

This documentation covers the example code snippets, explains the fixture design, and describes how they interact with pytest’s plugin and fixture systems.

Detailed Explanation

pytest_option(parser)


pytest_funcarg__accept(request)


class AcceptFixture

`AcceptFixture` provides helper methods and environment control for acceptance tests.

__init__(self, request)

run(self, *cmd)


Example acceptance test function

def test_some_acceptance_aspect(accept):
    accept.tmpdir.mkdir("somesub")
    result = accept.run("ls", "-la")
    assert "somesub" in result

Decorating a funcarg in a test module

def pytest_funcarg__accept(request):
    # Retrieve the original accept fixture
    arg = request.getfuncargvalue("accept")
    # Add a special directory for this test module
    arg.tmpdir.mkdir("special")
    return arg


class TestSpecialAcceptance:
    def test_sometest(self, accept):
        assert accept.tmpdir.join("special").check()

Implementation Details and Algorithms

Interactions with Other System Components

Visual Diagram

classDiagram
    class AcceptFixture {
        -tmpdir: py.path.local
        +__init__(request)
        +run(*cmd): str
    }

    pytest_funcarg__accept() --> AcceptFixture
    pytest_option(parser)
    test_some_acceptance_aspect(accept)
    pytest_funcarg__accept (module-level) --> AcceptFixture
    pytest_funcarg__accept (module-level) --> pytest_funcarg__accept (conftest)

Summary

This file serves as a practical example of extending pytest with acceptance testing capabilities. It covers:

Together, these patterns help maintain a clean separation between fast unit tests and slower acceptance tests, improving test suite performance and manageability.


**End of attic.rst documentation**