pkgs/cli: Move the test folder inside the python module
Move the `tests` folder to `clan_cli/tests`. As we now want part of our tests to live next to the functions that are tested - tests that are not in the `/tests` module also need access to the configured test fixtures that are exposed by the `pytest_plugins` declaration. The following folder structure doesn't support this model: ``` ├── clan_cli │ ├── api │ │ └── api_init_test.py ├── tests/ │ ├── conftest.py │ └── ... ``` Here `api_init_test.py` even when importing the test functions will not have the fixtures configured. There is a way to configure python to import the fixtures from another [`project/module`](https://docs.pytest.org/en/stable/how-to/fixtures.html#using-fixtures-from-other-projects), but this seems to *generally* be discouraged. So moving the `conftest.py` to the toplevel and the `/tests` folder into the toplevel seems to be a sensible choice choice.
This commit is contained in:
committed by
Johannes Kirschbauer
parent
a503c92c3e
commit
309c132b63
34
pkgs/clan-cli/clan_cli/tests/stdout.py
Normal file
34
pkgs/clan-cli/clan_cli/tests/stdout.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import types
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class CaptureOutput:
|
||||
def __init__(self, capsys: pytest.CaptureFixture) -> None:
|
||||
self.capsys = capsys
|
||||
self.capsys_disabled = capsys.disabled()
|
||||
self.capsys_disabled.__enter__()
|
||||
|
||||
def __enter__(self) -> "CaptureOutput":
|
||||
self.capsys_disabled.__exit__(None, None, None)
|
||||
self.capsys.readouterr()
|
||||
return self
|
||||
|
||||
def __exit__(
|
||||
self,
|
||||
exc_type: type[BaseException] | None,
|
||||
exc_value: BaseException | None,
|
||||
traceback: types.TracebackType | None,
|
||||
) -> None:
|
||||
res = self.capsys.readouterr()
|
||||
self.out = res.out
|
||||
self.err = res.err
|
||||
|
||||
# Disable capsys again
|
||||
self.capsys_disabled = self.capsys.disabled()
|
||||
self.capsys_disabled.__enter__()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def capture_output(capsys: pytest.CaptureFixture) -> CaptureOutput:
|
||||
return CaptureOutput(capsys)
|
||||
Reference in New Issue
Block a user