|
| 1 | +"""Synthetic fixtures for the sphinx_pytest_fixtures badge demo page. |
| 2 | +
|
| 3 | +Each fixture exercises one badge-slot combination so the demo page can show |
| 4 | +every permutation side-by-side: |
| 5 | +
|
| 6 | + Scope: session | module | class | function (suppressed — no badge) |
| 7 | + Kind: resource (suppressed) | factory | override_hook |
| 8 | + State: autouse | deprecated (set via RST :deprecated: option) |
| 9 | + Combos: session+factory, session+autouse |
| 10 | +
|
| 11 | +These fixtures are purely for documentation; they are never collected by |
| 12 | +pytest during a real test run (the module is not in the test tree). |
| 13 | +""" |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +import pytest |
| 18 | + |
| 19 | + |
| 20 | +@pytest.fixture |
| 21 | +def demo_plain() -> str: |
| 22 | + """Plain function-scope resource. Shows FIXTURE badge only.""" |
| 23 | + return "plain" |
| 24 | + |
| 25 | + |
| 26 | +@pytest.fixture(scope="session") |
| 27 | +def demo_session() -> str: |
| 28 | + """Session-scoped resource. Shows SESSION + FIXTURE badges.""" |
| 29 | + return "session" |
| 30 | + |
| 31 | + |
| 32 | +@pytest.fixture(scope="module") |
| 33 | +def demo_module() -> str: |
| 34 | + """Module-scoped resource. Shows MODULE + FIXTURE badges.""" |
| 35 | + return "module" |
| 36 | + |
| 37 | + |
| 38 | +@pytest.fixture(scope="class") |
| 39 | +def demo_class() -> str: |
| 40 | + """Class-scoped resource. Shows CLASS + FIXTURE badges.""" |
| 41 | + return "class" |
| 42 | + |
| 43 | + |
| 44 | +@pytest.fixture |
| 45 | +def demo_factory() -> type[str]: |
| 46 | + """Return a callable (factory kind). Shows FACTORY + FIXTURE badges.""" |
| 47 | + return str |
| 48 | + |
| 49 | + |
| 50 | +@pytest.fixture |
| 51 | +def demo_override_hook() -> str: |
| 52 | + """Override hook — customise in conftest.py. Shows OVERRIDE + FIXTURE badges.""" |
| 53 | + return "override" |
| 54 | + |
| 55 | + |
| 56 | +@pytest.fixture(autouse=True) |
| 57 | +def demo_autouse() -> None: |
| 58 | + """Autouse fixture. Shows AUTO + FIXTURE badges.""" |
| 59 | + |
| 60 | + |
| 61 | +@pytest.fixture |
| 62 | +def demo_deprecated() -> str: |
| 63 | + """Return a value (deprecated since 1.0, replaced by :func:`demo_plain`). |
| 64 | +
|
| 65 | + This fixture is documented with the ``deprecated`` RST option so the |
| 66 | + demo page can show the DEPRECATED + FIXTURE badge combination. |
| 67 | + """ |
| 68 | + return "deprecated" |
| 69 | + |
| 70 | + |
| 71 | +@pytest.fixture(scope="session") |
| 72 | +def demo_session_factory() -> type[str]: |
| 73 | + """Session-scoped factory. Shows SESSION + FACTORY + FIXTURE badges.""" |
| 74 | + return str |
| 75 | + |
| 76 | + |
| 77 | +@pytest.fixture(scope="session", autouse=True) |
| 78 | +def demo_session_autouse() -> None: |
| 79 | + """Session-scoped autouse. Shows SESSION + AUTO + FIXTURE badges.""" |
0 commit comments