test: Restructure test files

Extract the individual parsing tests (cli, env, rc) and add additional
configuration test file (TConf and config builder).

To extract the fixtures they have to go into an additional 'conftest.py'
file for pytest to recognize and automatically import them, see:
https://docs.pytest.org/en/stable/reference/fixtures.html#conftest-py-sharing-fixtures-across-multiple-files

and:
https://docs.pytest.org/en/stable/how-to/fixtures.html#using-fixtures-from-other-projects
This commit is contained in:
Marty Oehme 2025-11-29 11:18:48 +01:00
parent ff0e6cccfb
commit e50fc9444a
Signed by: Marty
GPG key ID: 4E535BC19C61886E
5 changed files with 201 additions and 112 deletions

27
test/conftest.py Normal file
View file

@ -0,0 +1,27 @@
from pathlib import Path
import pytest
from topen import OPTIONS
@pytest.fixture
def fake_id(monkeypatch):
monkeypatch.setattr("sys.argv", ["topen", "0"])
@pytest.fixture
def isolate_env(monkeypatch):
# delete all existing env vars that could interfere
monkeypatch.delenv("EDITOR", raising=False)
monkeypatch.delenv("VISUAL", raising=False)
for opt in OPTIONS.values():
if opt.env:
monkeypatch.delenv(opt.env, raising=False)
@pytest.fixture
def fake_rc(tmp_path: Path, monkeypatch):
rc = tmp_path / "test.taskrc"
monkeypatch.setattr(OPTIONS["task_rc"], "default", rc)
return rc