tests.conftest module

Fixtures, configuration and helpers for tests.

tests.conftest.httpserver_listen_address()[source]

Bind the local HTTP server to the loopback address, not to a name.

Overrides pytest-httpserver’s default of ("localhost", 0). Resolving that name is the one thing the tests/test_config.py cases serving a configuration file over HTTP need from the host, and a build sandbox is exactly where it is unavailable: the Nix one on macOS denies the lookup, so every one of them errors out with socket.gaierror: [Errno 8] nodename nor servname provided, or not known.

Binding the literal address asks nothing of the resolver. Whether a sandbox additionally gates the loopback socket is its own policy, and a separate question: this only removes the lookup that failed first.

tests.conftest.requires_process_table()[source]

Skip a test where the process table does not list the test’s own process.

The kill paths of run_cli find a command’s descendants in the process table. Linux reads it from /proc. Elsewhere it comes from ps, which a build sandbox can deny: the MacPorts test phase gets an empty listing, so the kill tests would fail on what the sandbox hides rather than on the code.

The probe runs ps itself instead of _posix_process_table(), so a regression that empties the table still fails those tests.

tests.conftest.skip_windows_colors = MarkDecorator(mark=Mark(name='skipif', args=(<extra_platforms.pytest._DeferredCondition object>,), kwargs={'reason': 'Click overstrip colors on Windows'}))

Skips color tests on Windows as click.testing.invoke overzealously strips colors.

See: - https://github.com/pallets/click/issues/2111 - https://github.com/pallets/click/issues/2110

tests.conftest.TRANSIENT_STATUS_CODES = frozenset({408, 425, 429, 500, 502, 503, 504})

Status codes a host answers with when it is refusing this request rather than reporting something about the resource: a rate limit, a proxy hiccup, or a service that is briefly down.

tests.conftest.fetch_or_skip(url, timeout=60)[source]

Fetch url, skipping the test when the failure says nothing about it.

A network-dependent test asserts something about what a host serves. It cannot assert it while the host is rate-limiting, timing out, or down, and a bare assert response.ok there reports assert False: a red run that looks like the finding the test exists to make, with nothing naming the cause. GitHub throttles anonymous archive downloads, so a full-suite run hits this on its own schedule and reads as an order-dependent flake.

A response that is about the resource still fails, loudly and with its status: a 404 means the URL these tests build no longer resolves, which is the finding, not the weather.

Return type:

Response

tests.conftest.walk_commands(command, ctx=None, path=())[source]

Yield every (path, command) pair under command, itself included.

path holds the subcommand names leading to the command, the root’s own name excluded, so joining it names the invocation a user would type.

Parameters:
  • command (Command) – the command to walk, a group or a leaf.

  • ctx (Context | None) – the context command is looked up in. Built from the command itself when omitted, which is what a walk starting at the root wants.

  • path (tuple[str, ...]) – the names already walked through, for the recursion.

Return type:

Iterator[tuple[tuple[str, ...], Command]]

class tests.conftest.TTYStringIO(initial_value='', newline='\n')[source]

Bases: StringIO

An in-memory text buffer that claims to be an interactive terminal.

isatty()[source]

Return whether this is an ‘interactive’ stream.

Return False if it can’t be determined.

Return type:

bool

class tests.conftest.StallingTTY[source]

Bases: TTYStringIO

A terminal whose writes block once stall is set, until release is.

Stands in for a terminal paused by flow control (Ctrl+S), or a full pipe.

write(text)[source]

Write string to file.

Returns the number of characters written, which is always equal to the length of the string.

Return type:

int

tests.conftest.wait_until(predicate, timeout=3.0)[source]

Poll predicate until it is true or timeout seconds elapse.

Lets thread-driven assertions wait for an outcome instead of sleeping a fixed (and racy) amount.

Return type:

bool