Pytest Plugins — Enable & Fixtures¶
Enabling the pybuggy plugins gives a test suite the fixtures of every activated test kind:
the api fixture of the api plugin, the sandbox fixture, the web fixture — each gated
on its own activation sources, one install() call for all.
Enable the plugins¶
Call goga_tool_pybuggy.plugins.install() from the root conftest.py:
# conftest.py
from dotenv import load_dotenv
load_dotenv()
from goga_tool_pybuggy import plugins
plugins.install()
load_dotenv() runs before install() so plugin options (resolved from os.environ)
see the .env values; the argumentless call keeps override=False (CI/operator-exported
variables win).
There is no import-time auto-wiring:
pytest_plugins = ["goga_tool_pybuggy.plugins"]alone does NOT enable the plugin — the explicitinstall()call is required.
goga tool pybuggy init generates this conftest.py for you when it is absent — an
existing file is kept (bare mode: unless you confirm the overwrite) — see
CLI — init.
The install() call installs the api plugin when the api document exists:
.goga/tools/pybuggy/api.yml. With the document, the api fixture, the plugin CLI
options, and the generated-fixture discovery are registered; without it, nothing
api-related is registered — a web-only or sandbox-only project runs with no base_url
at all, and a test requesting the api fixture gets pytest's standard
fixture 'api' not found (BASE_URL stays a value source for the option, never an
activation source for the plugin).
The same install() call installs the sandbox plugin: when
.goga/tools/pybuggy/sandbox.yml exists under the pybuggy tools home, the product
sandbox fixture appears — the sandbox starts lazily on the first test that requests
it, per-test resets and marked presets are product-owned, and a test binds its api to
the sandbox explicitly through endpoint.bind(sandbox) — every request then first
applies the test's pending sandbox data (see Sandbox).
The same install() call installs the web plugin as well: when
.goga/tools/pybuggy/web.yml exists, the web fixture appears — the per-test browser
runtime of the web test kind, where every step sentence becomes Playwright code once and
replays from the committed cache (see Web). The document is validated
at pytest configuration — an invalid web.yml fails the run before any collection;
without it nothing web-related is registered and a test requesting web fails with
pytest's standard fixture 'web' not found.
What enabling wires¶
- CLI options —
--base-url(resolvesbase_url, required; a typed flag overrides the config-file andBASE_URLvalue; it governs the tests that do not bind their api to the sandbox — a bound test takes the sandbox address),--api-timeout(resolvestimeout),--retries(the flaky rerun count),--api-assert-timeout/--api-assert-delay(the assert-polling baseline). The remaining options (headers,assert_field_class,assert_response_class) have no CLI flag — config-file only. See Configuration. - Web CLI options —
--strict-mode(replay-only: zero LLM calls, a cache miss fails the test) and--interactive(interactive step healing), bothstore_trueflags of the web plugin; a typed flag forces its mode on — never off; and--browser-endpoint <url>(a value option overridingbrowser.endpointofweb.ymlfor the run — a typed empty string forces the local launch; an invalid value fails at pytest configuration). See Web — run modes. base_urltemplate — a Jinja2 template rendered once atpytest_configureagainstos.environ+ the CLI options you actually passed. Placeholders fed from the CLI require registering those options viapytest_addoptioninconftest.py.- Flaky reruns — when
retriesresolves to a positive int, every collected test without an existing flaky marker is stamped withpytest.mark.flaky(max_runs=retries). The reruns take effect when theflakypackage is installed in the consumer suite; a programmatic default can be passed asinstall(default_retries=N). - The
apifixture — function-scoped, yields the HTTP client built from the resolved options and closes it after the test; the client carries the rendered staticbase_url. Binding an address is explicit in the test body:endpoint.bind(sandbox)(orapi.bind(sandbox)) replaces the address with the sandbox's service address and installs the request pre-flight — pending data is applied, the service liveness is ensured, then the request runs; a dead service fails the request with the service output attached. Every other test uses the rendered staticbase_urlwith no pre-flight. Generated endpoint fixtures depend on it; pytest resolvesapiautomatically — no extra wiring:
@pytest.fixture(scope="function")
def get_orders(api: Api) -> Endpoint:
return Endpoint(api, "/orders", method="GET")
- Recursive generated-fixture loading —
install()defaultsloadersto[PackageLoader("api", required=False)], so every generatedapi/<spec>/<id>/api.pymodule is discovered and loaded through the recursivepytest_pluginslist, out of the box.
Overriding discovery¶
Pass an explicit loaders to install(), or add a loader section to the config to do
it declaratively (details: Loaders):
goga_tool_pybuggy.plugins.install(loaders=[PackageLoader("api"), PackageLoader("service")])
goga_tool_pybuggy.plugins.install(loaders=[]) # disable discovery entirely
# .goga/tools/pybuggy/api.yml
loader:
packages:
- name: api # walk the api/ package tree (dots map to path separators)
required: false # tolerate a missing tree
modules:
- my_plugin.conftest
Preconditions and side effects¶
- The api plugin activates when
.goga/tools/pybuggy/api.ymlexists; its requiredbase_urlthen resolves from the document key, theBASE_URLenv, or a typed--base-url— a missing resolution across all three fails the run at pytest configuration (the required-option error of the plugin framework). - A sandbox document at
.goga/tools/pybuggy/sandbox.ymlinstalls the sandbox plugin on the sameinstall()call (the productsandboxfixture); the environment then needs a docker-compatible container runtime, but only when the run actually has sandbox tests — the containers start on the first one (see Sandbox). - A web document at
.goga/tools/pybuggy/web.ymlinstalls the web plugin on the sameinstall()call (thewebfixture); the environment then needs the playwright browser binaries —playwright install --with-deps <browser>— but only when the run actually has web tests (see Web). - The
api/tree is discovered by default when the api plugin is active; a missing tree is tolerated (required=False). - Loader paths walk the filesystem relative to the current working directory (while
candidate imports go through
sys.path). Runpytestfrom the project root — the directory that both containsapi/and is onsys.path. Running from another directory makes discovery silently return[], so generated fixtures are not loaded and tests fail withfixture '<name>' not found.
Test reruns¶
Two mechanisms exist:
- Suite-wide — the
retriesoption (orinstall(default_retries=N)) stamps every collected test without an existing flaky marker; requires theflakypackage in the suite. - Per-test decorator — the facade
retriesdecorator (from goga_tool_pybuggy import retries; built on theflakypackage):@retries(max_runs=3, min_passes=2, delay=1)reruns a flaky test up tomax_runstimes requiringmin_passessuccesses, pausingdelayseconds between reruns.