pytest-model-lib 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ # Python files
2
+ __pycache__/
3
+ **/.pytest_cache
4
+ *.pyc
5
+ .venv/
6
+ .venv-ci/
7
+ .ruff_cache
8
+ .coverage
9
+
10
+ # Pants workspace files
11
+ /.pants.d/
12
+ /dist
13
+ **/.pids
14
+ /.pants.workdir.file_lock*
15
+
16
+ # Editors
17
+ .idea/
18
+ *.iml
19
+
20
+ # docs
21
+ site
22
+ .cache
23
+ docs/
@@ -0,0 +1,4 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytest-model-lib
3
+ Version: 0.0.1
4
+ Requires-Python: >=3.12
@@ -0,0 +1,21 @@
1
+ [project]
2
+ name = "pytest-model-lib"
3
+ version = "0.0.1"
4
+ requires-python = ">=3.12"
5
+
6
+ [project.entry-points.pytest11]
7
+ model_lib = "pytest_model_lib.plugin"
8
+
9
+ [build-system]
10
+ requires = ["hatchling"]
11
+ build-backend = "hatchling.build"
12
+
13
+ [tool.hatch.build.targets.sdist]
14
+ include = [
15
+ "pytest_model_lib/*.py",
16
+ ]
17
+ exclude = [
18
+ "*_test.py",
19
+ "conftest.py",
20
+ "test_*.json",
21
+ ]
@@ -0,0 +1,3 @@
1
+ from pytest_model_lib.plugin import static_env_vars
2
+
3
+ __all__ = ["static_env_vars"]
@@ -0,0 +1,66 @@
1
+ import logging
2
+ import os
3
+
4
+ import pytest
5
+ from _pytest.python import CallSpec2
6
+ from model_lib import StaticSettings
7
+
8
+ logger = logging.getLogger(__name__)
9
+
10
+
11
+ @pytest.fixture
12
+ def static_env_vars(tmp_path, monkeypatch) -> StaticSettings:
13
+ settings = StaticSettings.for_testing(tmp_path=tmp_path)
14
+ monkeypatch.setenv("STATIC_DIR", str(settings.STATIC_DIR))
15
+ monkeypatch.setenv("CACHE_DIR", str(settings.CACHE_DIR))
16
+ return settings
17
+
18
+
19
+ def _fixture_has_skip_marker(fixture_name: str, fixture_def) -> bool:
20
+ markers = getattr(fixture_def.func, "pytestmark", [])
21
+ return any(marker.name.startswith("skip") for marker in markers)
22
+
23
+
24
+ def _skip_marked_tests() -> bool:
25
+ return os.getenv("SKIP_MARKED_TESTS", "false").lower() in ("true", "1", "yes")
26
+
27
+
28
+ def pytest_collection_modifyitems(config, items):
29
+ """Skip tests that are marked with @pytest.mark.skip
30
+ To avoid the terminal session in VS Code that might have extra env-vars set accidentally run marked tests"""
31
+ if not _skip_marked_tests():
32
+ return
33
+ for item in items:
34
+ if any(marker.name.startswith("skip") for marker in item.own_markers):
35
+ item.add_marker(
36
+ pytest.mark.skip(
37
+ reason="Skipping test due to SKIP_MARKED_TESTS environment variable"
38
+ )
39
+ )
40
+ continue
41
+ item_session: pytest.Session = item.session
42
+ fixture_manager = item_session._fixturemanager
43
+ call_spec: CallSpec2 | None = getattr(item, "callspec", None)
44
+ for fixture_name in item.fixturenames:
45
+ if (
46
+ fixture_name == "request"
47
+ or call_spec
48
+ and fixture_name in call_spec.params
49
+ ):
50
+ continue
51
+ fixturedefs: list = fixture_manager.getfixturedefs(fixture_name, item) # type: ignore
52
+ if not fixturedefs:
53
+ logger.warning(
54
+ f"No fixture definitions found for {fixture_name} in {item}"
55
+ )
56
+ continue
57
+ assert len(fixturedefs) == 1, (
58
+ f"Expected one fixture definition for {fixture_name}, got {len(fixturedefs)}"
59
+ )
60
+ if _fixture_has_skip_marker(fixture_name, fixturedefs[0]):
61
+ item.add_marker(
62
+ pytest.mark.skip(
63
+ reason=f"Skipping test due to fixture {fixture_name} having skip marker"
64
+ )
65
+ )
66
+ break