diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-11-13 18:35:03 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-11-13 18:35:03 +0100 |
commit | eac4f7a7f7fec9585a7c080400c4ae8fa9b67578 (patch) | |
tree | 21932471bf6fbe7ba424cae1223bf6468d8176d5 /tests | |
parent | 9a31dd6651d8a47943e63db212bce7245a152450 (diff) | |
download | fietsboek-eac4f7a7f7fec9585a7c080400c4ae8fa9b67578.tar.gz fietsboek-eac4f7a7f7fec9585a7c080400c4ae8fa9b67578.tar.bz2 fietsboek-eac4f7a7f7fec9585a7c080400c4ae8fa9b67578.zip |
make test app fixture module-scoped
Previously, we had it session-scoped, which meant that the app was
created once for all tests. This doesn't allow us to play with different
settings however, such as disabling account registration or image
uploads and testing that.
Now, the fixtures are module scoped, which means that we still save on
prepare/teardown time a bit, but we're also a bit more flexible. By
making new test modules, we can test different settings there.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conftest.py | 9 | ||||
-rw-r--r-- | tests/playwright/conftest.py | 4 |
2 files changed, 8 insertions, 5 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index a4366ab..94f795a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -28,11 +28,14 @@ def ini_file(request): # potentially grab this path from a pytest option return os.path.abspath(request.config.option.ini or 'testing.ini') -@pytest.fixture(scope='session') +# Even though the ini file is scoped to session, we scope the actual settings +# to module only. This way, we can test different configurations in different +# modules. +@pytest.fixture(scope='module') def app_settings(ini_file): return get_appsettings(ini_file) -@pytest.fixture(scope='session') +@pytest.fixture(scope='module') def dbengine(app_settings, ini_file): engine = models.get_engine(app_settings) @@ -73,7 +76,7 @@ def _cleanup_data(app_settings): if (data_dir / "tracks").is_dir(): shutil.rmtree(data_dir / "tracks") -@pytest.fixture(scope='session') +@pytest.fixture(scope='module') def app(app_settings, dbengine, tmp_path_factory): app_settings["fietsboek.data_dir"] = str(tmp_path_factory.mktemp("data")) logging.getLogger().setLevel(logging.DEBUG) diff --git a/tests/playwright/conftest.py b/tests/playwright/conftest.py index 12a0047..4e7f5a4 100644 --- a/tests/playwright/conftest.py +++ b/tests/playwright/conftest.py @@ -15,7 +15,7 @@ from fietsboek.config import Config import pytest -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def server_port(): """Return a (likely) free port. @@ -29,7 +29,7 @@ def server_port(): return port -@pytest.fixture(scope="session", autouse=True) +@pytest.fixture(scope="module", autouse=True) def running_server(server_port, app): """Have the app running as an actual server.""" server = simple_server.make_server("127.0.0.1", server_port, app) |