diff --git a/tests/cli/conftest.py b/tests/cli/conftest.py index 74cefc1..219045c 100644 --- a/tests/cli/conftest.py +++ b/tests/cli/conftest.py @@ -1,15 +1,31 @@ -from collections.abc import Callable +from collections.abc import Callable, Iterator import pytest +import structlog from anycastd._cli.main import app from click.testing import Result from typer.testing import CliRunner @pytest.fixture -def anycastd_cli() -> Callable[..., Result]: +def reset_structlog_config() -> Iterator[None]: + """Reset structlog configuration after running a test. + + This is required for tests that invoke the anycastd CLI, as running it + initializes the structlog configuration, adding filters that could affect + other tests. + """ + yield + structlog.reset_defaults() + + +@pytest.fixture +def anycastd_cli(reset_structlog_config) -> Callable[..., Result]: """A callable that runs anycastd CLI commands. + To make sure that this fixture does not affect other tests, state that is + initialized when running the CLI needs to be reset after using this fixture. + Example: ```python >>> result = anycastd_cli("run", "--help") diff --git a/tests/cli/test_main.py b/tests/cli/test_main.py index daa7944..e6e2be1 100644 --- a/tests/cli/test_main.py +++ b/tests/cli/test_main.py @@ -101,9 +101,6 @@ def test_log_format_configures_structlog(self, anycastd_cli, arg: str, processor assert isinstance(last_processor, processor) -@pytest.mark.xfail( - reason="Above tests configure a persistent log level filter.", strict=False -) def test_reading_configuration_is_logged(mocker): """Reading the configuration is logged.""" path = Path("/path/to/config.toml")