pytest-depends-on 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.
- pytest_depends_on-0.0.1/LICENSE +21 -0
- pytest_depends_on-0.0.1/MANIFEST.in +3 -0
- pytest_depends_on-0.0.1/PKG-INFO +127 -0
- pytest_depends_on-0.0.1/README.md +97 -0
- pytest_depends_on-0.0.1/pyproject.toml +47 -0
- pytest_depends_on-0.0.1/pytest_depends_on/__init__.py +7 -0
- pytest_depends_on-0.0.1/pytest_depends_on/consts/__init__.py +0 -0
- pytest_depends_on-0.0.1/pytest_depends_on/consts/status.py +9 -0
- pytest_depends_on-0.0.1/pytest_depends_on/depends_on.py +56 -0
- pytest_depends_on-0.0.1/pytest_depends_on.egg-info/PKG-INFO +127 -0
- pytest_depends_on-0.0.1/pytest_depends_on.egg-info/SOURCES.txt +21 -0
- pytest_depends_on-0.0.1/pytest_depends_on.egg-info/dependency_links.txt +1 -0
- pytest_depends_on-0.0.1/pytest_depends_on.egg-info/entry_points.txt +2 -0
- pytest_depends_on-0.0.1/pytest_depends_on.egg-info/requires.txt +9 -0
- pytest_depends_on-0.0.1/pytest_depends_on.egg-info/top_level.txt +1 -0
- pytest_depends_on-0.0.1/setup.cfg +4 -0
- pytest_depends_on-0.0.1/tests/test_class.py +54 -0
- pytest_depends_on-0.0.1/tests/test_multi_parent.py +48 -0
- pytest_depends_on-0.0.1/tests/test_parent_failed.py +18 -0
- pytest_depends_on-0.0.1/tests/test_parent_parametrize.py +49 -0
- pytest_depends_on-0.0.1/tests/test_parent_passed.py +17 -0
- pytest_depends_on-0.0.1/tests/test_parent_skip.py +18 -0
- pytest_depends_on-0.0.1/tests/test_with_default_param.py +40 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Avi Zaguri
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pytest-depends-on
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Python package for managing test dependencies in pytest.
|
|
5
|
+
Author: Avi Zaguri
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/aviz92/pytest-depends-on
|
|
8
|
+
Project-URL: Repository, https://github.com/aviz92/pytest-depends-on
|
|
9
|
+
Project-URL: Issues, https://github.com/aviz92/pytest-depends-on/issues
|
|
10
|
+
Keywords: development,python,pytest,pytest-dependensies,dependensies,testing,automation
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Framework :: Pytest
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Topic :: System :: Logging
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: build>=1.3.0
|
|
21
|
+
Requires-Dist: colorlog>=6.10.1
|
|
22
|
+
Requires-Dist: custom-python-logger>=2.0.10
|
|
23
|
+
Requires-Dist: pre-commit>=4.5.0
|
|
24
|
+
Requires-Dist: pytest>=9.0.1
|
|
25
|
+
Requires-Dist: python-dotenv>=1.2.1
|
|
26
|
+
Requires-Dist: setuptools>=80.9.0
|
|
27
|
+
Requires-Dist: twine>=6.2.0
|
|
28
|
+
Requires-Dist: wheel>=0.45.1
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# pytest-depends-on
|
|
32
|
+
|
|
33
|
+
An advanced pytest plugin designed for Python projects, offering robust dependency management utilities to enhance the testing workflow. <br>
|
|
34
|
+
It allows tests to be skipped based on the execution status of other tests, ensuring that dependent tests do not run if their prerequisites fail or are skipped, resulting in a cleaner and more efficient testing experience.
|
|
35
|
+
|
|
36
|
+
-----
|
|
37
|
+
|
|
38
|
+
## 🚀 Features
|
|
39
|
+
- ✅ **depends-on**: A powerful marker to declare test dependencies. If a parent test fails or hasn't run, the dependent test is automatically skipped.
|
|
40
|
+
- **Marker:** `@pytest.mark.depends_on`
|
|
41
|
+
- **Arguments:**
|
|
42
|
+
- `tests` (list): A list of parent test names (node IDs) that the current test depends on.
|
|
43
|
+
- `status` (optional): The expected status of the parent test. Defaults to `PASSED`. The dependent test will skip if the parent status does not match this value.
|
|
44
|
+
- `allowed_not_run` (optional): Boolean. If `True`, the test will not skip if the parent test has not run yet. Defaults to `False` (skips if parent is missing).
|
|
45
|
+
<br> <br>
|
|
46
|
+
- ✅ **Automatic Status Tracking**: Automatically tracks the result (`passed`, `failed`, `skipped`, `xfailed`, `xpassed`) of every test during the `call` phase to resolve dependencies dynamically.
|
|
47
|
+
|
|
48
|
+
-----
|
|
49
|
+
|
|
50
|
+
## 📦 Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install pytest-depends-on
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
-----
|
|
57
|
+
|
|
58
|
+
### 🔧 Usage
|
|
59
|
+
|
|
60
|
+
#### 1\. Register the marker
|
|
61
|
+
|
|
62
|
+
Add the marker to your `pytest.ini` file to avoid warnings (optional, as the plugin programmatically registers it, but good practice):
|
|
63
|
+
|
|
64
|
+
```ini
|
|
65
|
+
[pytest]
|
|
66
|
+
markers =
|
|
67
|
+
depends_on: mark test as dependent on another test
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### 2\. Implement in your tests
|
|
71
|
+
|
|
72
|
+
Use the marker decorator on your test functions.
|
|
73
|
+
|
|
74
|
+
**Basic Dependency:**
|
|
75
|
+
`test_child` will only run if `test_parent` passes.
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import pytest
|
|
79
|
+
|
|
80
|
+
def test_parent():
|
|
81
|
+
assert True
|
|
82
|
+
|
|
83
|
+
@pytest.mark.depends_on(tests=["test_parent"])
|
|
84
|
+
def test_child():
|
|
85
|
+
assert True
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Custom Status Dependency:**
|
|
89
|
+
`test_child` will run only if `test_parent` fails (useful for testing error handling or recovery).
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
import pytest
|
|
93
|
+
|
|
94
|
+
from pytest_depends_on.consts.status import Status
|
|
95
|
+
|
|
96
|
+
@pytest.mark.depends_on(tests=["test_parent"], status=Status.FAILED)
|
|
97
|
+
def test_child():
|
|
98
|
+
pass
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Soft Dependency:**
|
|
102
|
+
`test_child` will run even if `test_parent` hasn't executed yet (e.g., due to ordering).
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
import pytest
|
|
106
|
+
|
|
107
|
+
@pytest.mark.depends_on(tests=["test_parent"], allowed_not_run=True)
|
|
108
|
+
def test_child():
|
|
109
|
+
pass
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
-----
|
|
113
|
+
|
|
114
|
+
## 🤝 Contributing
|
|
115
|
+
|
|
116
|
+
If you have a helpful tool, pattern, or improvement to suggest:
|
|
117
|
+
Fork the repo <br>
|
|
118
|
+
Create a new branch <br>
|
|
119
|
+
Submit a pull request <br>
|
|
120
|
+
I welcome additions that promote clean, productive, and maintainable development. <br>
|
|
121
|
+
|
|
122
|
+
-----
|
|
123
|
+
|
|
124
|
+
## 🙏 Thanks
|
|
125
|
+
|
|
126
|
+
Thanks for exploring this repository\! <br>
|
|
127
|
+
Happy coding\! <br>
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# pytest-depends-on
|
|
2
|
+
|
|
3
|
+
An advanced pytest plugin designed for Python projects, offering robust dependency management utilities to enhance the testing workflow. <br>
|
|
4
|
+
It allows tests to be skipped based on the execution status of other tests, ensuring that dependent tests do not run if their prerequisites fail or are skipped, resulting in a cleaner and more efficient testing experience.
|
|
5
|
+
|
|
6
|
+
-----
|
|
7
|
+
|
|
8
|
+
## 🚀 Features
|
|
9
|
+
- ✅ **depends-on**: A powerful marker to declare test dependencies. If a parent test fails or hasn't run, the dependent test is automatically skipped.
|
|
10
|
+
- **Marker:** `@pytest.mark.depends_on`
|
|
11
|
+
- **Arguments:**
|
|
12
|
+
- `tests` (list): A list of parent test names (node IDs) that the current test depends on.
|
|
13
|
+
- `status` (optional): The expected status of the parent test. Defaults to `PASSED`. The dependent test will skip if the parent status does not match this value.
|
|
14
|
+
- `allowed_not_run` (optional): Boolean. If `True`, the test will not skip if the parent test has not run yet. Defaults to `False` (skips if parent is missing).
|
|
15
|
+
<br> <br>
|
|
16
|
+
- ✅ **Automatic Status Tracking**: Automatically tracks the result (`passed`, `failed`, `skipped`, `xfailed`, `xpassed`) of every test during the `call` phase to resolve dependencies dynamically.
|
|
17
|
+
|
|
18
|
+
-----
|
|
19
|
+
|
|
20
|
+
## 📦 Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install pytest-depends-on
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
-----
|
|
27
|
+
|
|
28
|
+
### 🔧 Usage
|
|
29
|
+
|
|
30
|
+
#### 1\. Register the marker
|
|
31
|
+
|
|
32
|
+
Add the marker to your `pytest.ini` file to avoid warnings (optional, as the plugin programmatically registers it, but good practice):
|
|
33
|
+
|
|
34
|
+
```ini
|
|
35
|
+
[pytest]
|
|
36
|
+
markers =
|
|
37
|
+
depends_on: mark test as dependent on another test
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
#### 2\. Implement in your tests
|
|
41
|
+
|
|
42
|
+
Use the marker decorator on your test functions.
|
|
43
|
+
|
|
44
|
+
**Basic Dependency:**
|
|
45
|
+
`test_child` will only run if `test_parent` passes.
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import pytest
|
|
49
|
+
|
|
50
|
+
def test_parent():
|
|
51
|
+
assert True
|
|
52
|
+
|
|
53
|
+
@pytest.mark.depends_on(tests=["test_parent"])
|
|
54
|
+
def test_child():
|
|
55
|
+
assert True
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Custom Status Dependency:**
|
|
59
|
+
`test_child` will run only if `test_parent` fails (useful for testing error handling or recovery).
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import pytest
|
|
63
|
+
|
|
64
|
+
from pytest_depends_on.consts.status import Status
|
|
65
|
+
|
|
66
|
+
@pytest.mark.depends_on(tests=["test_parent"], status=Status.FAILED)
|
|
67
|
+
def test_child():
|
|
68
|
+
pass
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Soft Dependency:**
|
|
72
|
+
`test_child` will run even if `test_parent` hasn't executed yet (e.g., due to ordering).
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import pytest
|
|
76
|
+
|
|
77
|
+
@pytest.mark.depends_on(tests=["test_parent"], allowed_not_run=True)
|
|
78
|
+
def test_child():
|
|
79
|
+
pass
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
-----
|
|
83
|
+
|
|
84
|
+
## 🤝 Contributing
|
|
85
|
+
|
|
86
|
+
If you have a helpful tool, pattern, or improvement to suggest:
|
|
87
|
+
Fork the repo <br>
|
|
88
|
+
Create a new branch <br>
|
|
89
|
+
Submit a pull request <br>
|
|
90
|
+
I welcome additions that promote clean, productive, and maintainable development. <br>
|
|
91
|
+
|
|
92
|
+
-----
|
|
93
|
+
|
|
94
|
+
## 🙏 Thanks
|
|
95
|
+
|
|
96
|
+
Thanks for exploring this repository\! <br>
|
|
97
|
+
Happy coding\! <br>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pytest-depends-on"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "A Python package for managing test dependencies in pytest."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Avi Zaguri" },]
|
|
13
|
+
keywords = ["development", "python", "pytest", "pytest-dependensies", "dependensies", "testing", "automation"]
|
|
14
|
+
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Framework :: Pytest",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Topic :: System :: Logging",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
dependencies = [
|
|
25
|
+
"build>=1.3.0",
|
|
26
|
+
"colorlog>=6.10.1",
|
|
27
|
+
"custom-python-logger>=2.0.10",
|
|
28
|
+
"pre-commit>=4.5.0",
|
|
29
|
+
"pytest>=9.0.1",
|
|
30
|
+
"python-dotenv>=1.2.1",
|
|
31
|
+
"setuptools>=80.9.0",
|
|
32
|
+
"twine>=6.2.0",
|
|
33
|
+
"wheel>=0.45.1",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://github.com/aviz92/pytest-depends-on"
|
|
38
|
+
Repository = "https://github.com/aviz92/pytest-depends-on"
|
|
39
|
+
Issues = "https://github.com/aviz92/pytest-depends-on/issues"
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.packages.find]
|
|
42
|
+
where = ["."]
|
|
43
|
+
include = ["pytest_depends_on*"]
|
|
44
|
+
namespaces = false
|
|
45
|
+
|
|
46
|
+
[project.entry-points.pytest11]
|
|
47
|
+
depend_on = "pytest_depends_on.depends_on"
|
|
File without changes
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from _pytest.config import Config
|
|
3
|
+
from _pytest.fixtures import FixtureRequest
|
|
4
|
+
from _pytest.python import Function
|
|
5
|
+
from custom_python_logger import get_logger
|
|
6
|
+
|
|
7
|
+
from pytest_depends_on.consts.status import Status
|
|
8
|
+
|
|
9
|
+
test_results = {}
|
|
10
|
+
|
|
11
|
+
logger = get_logger("pytest_depends_on")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
|
15
|
+
def pytest_runtest_makereport(item: Function) -> None:
|
|
16
|
+
outcome = yield
|
|
17
|
+
report = outcome.get_result()
|
|
18
|
+
|
|
19
|
+
if report.when != "call":
|
|
20
|
+
return
|
|
21
|
+
|
|
22
|
+
test_name = item.nodeid.split(".py::")[-1]
|
|
23
|
+
if hasattr(report, "wasxfail"):
|
|
24
|
+
if report.skipped:
|
|
25
|
+
test_results[test_name] = Status.XFAILED
|
|
26
|
+
elif report.passed:
|
|
27
|
+
test_results[test_name] = Status.XPASS
|
|
28
|
+
else:
|
|
29
|
+
test_results[test_name] = report.outcome
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@pytest.fixture(autouse=True)
|
|
33
|
+
def check_dependency(request: FixtureRequest) -> None:
|
|
34
|
+
if marker := request.node.get_closest_marker("depends_on"):
|
|
35
|
+
parent_result_expected = marker.kwargs.get("status", Status.PASSED)
|
|
36
|
+
allowed_parent_not_run = marker.kwargs.get("allowed_not_run", False)
|
|
37
|
+
for parent_test in marker.kwargs["tests"]:
|
|
38
|
+
if isinstance(parent_test, dict):
|
|
39
|
+
parent_test_name = parent_test.get("name")
|
|
40
|
+
parent_result_expected = parent_test.get("status", parent_result_expected)
|
|
41
|
+
allowed_parent_not_run = parent_test.get("allowed_not_run", allowed_parent_not_run)
|
|
42
|
+
else:
|
|
43
|
+
parent_test_name = parent_test
|
|
44
|
+
|
|
45
|
+
parent_result = test_results.get(parent_test_name)
|
|
46
|
+
|
|
47
|
+
if allowed_parent_not_run and parent_result is None:
|
|
48
|
+
continue
|
|
49
|
+
if not parent_result:
|
|
50
|
+
pytest.skip(f"Test skipped: Dependency '{parent_test_name}' has not run yet.")
|
|
51
|
+
if parent_result != parent_result_expected:
|
|
52
|
+
pytest.skip(f"Test skipped: Dependency '{parent_test_name}' did not pass (status: {parent_result}).")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def pytest_configure(config: Config) -> None:
|
|
56
|
+
config.addinivalue_line("markers", "depends_on(name): mark test as dependent on another test")
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pytest-depends-on
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Python package for managing test dependencies in pytest.
|
|
5
|
+
Author: Avi Zaguri
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/aviz92/pytest-depends-on
|
|
8
|
+
Project-URL: Repository, https://github.com/aviz92/pytest-depends-on
|
|
9
|
+
Project-URL: Issues, https://github.com/aviz92/pytest-depends-on/issues
|
|
10
|
+
Keywords: development,python,pytest,pytest-dependensies,dependensies,testing,automation
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Framework :: Pytest
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Topic :: System :: Logging
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: build>=1.3.0
|
|
21
|
+
Requires-Dist: colorlog>=6.10.1
|
|
22
|
+
Requires-Dist: custom-python-logger>=2.0.10
|
|
23
|
+
Requires-Dist: pre-commit>=4.5.0
|
|
24
|
+
Requires-Dist: pytest>=9.0.1
|
|
25
|
+
Requires-Dist: python-dotenv>=1.2.1
|
|
26
|
+
Requires-Dist: setuptools>=80.9.0
|
|
27
|
+
Requires-Dist: twine>=6.2.0
|
|
28
|
+
Requires-Dist: wheel>=0.45.1
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# pytest-depends-on
|
|
32
|
+
|
|
33
|
+
An advanced pytest plugin designed for Python projects, offering robust dependency management utilities to enhance the testing workflow. <br>
|
|
34
|
+
It allows tests to be skipped based on the execution status of other tests, ensuring that dependent tests do not run if their prerequisites fail or are skipped, resulting in a cleaner and more efficient testing experience.
|
|
35
|
+
|
|
36
|
+
-----
|
|
37
|
+
|
|
38
|
+
## 🚀 Features
|
|
39
|
+
- ✅ **depends-on**: A powerful marker to declare test dependencies. If a parent test fails or hasn't run, the dependent test is automatically skipped.
|
|
40
|
+
- **Marker:** `@pytest.mark.depends_on`
|
|
41
|
+
- **Arguments:**
|
|
42
|
+
- `tests` (list): A list of parent test names (node IDs) that the current test depends on.
|
|
43
|
+
- `status` (optional): The expected status of the parent test. Defaults to `PASSED`. The dependent test will skip if the parent status does not match this value.
|
|
44
|
+
- `allowed_not_run` (optional): Boolean. If `True`, the test will not skip if the parent test has not run yet. Defaults to `False` (skips if parent is missing).
|
|
45
|
+
<br> <br>
|
|
46
|
+
- ✅ **Automatic Status Tracking**: Automatically tracks the result (`passed`, `failed`, `skipped`, `xfailed`, `xpassed`) of every test during the `call` phase to resolve dependencies dynamically.
|
|
47
|
+
|
|
48
|
+
-----
|
|
49
|
+
|
|
50
|
+
## 📦 Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install pytest-depends-on
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
-----
|
|
57
|
+
|
|
58
|
+
### 🔧 Usage
|
|
59
|
+
|
|
60
|
+
#### 1\. Register the marker
|
|
61
|
+
|
|
62
|
+
Add the marker to your `pytest.ini` file to avoid warnings (optional, as the plugin programmatically registers it, but good practice):
|
|
63
|
+
|
|
64
|
+
```ini
|
|
65
|
+
[pytest]
|
|
66
|
+
markers =
|
|
67
|
+
depends_on: mark test as dependent on another test
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### 2\. Implement in your tests
|
|
71
|
+
|
|
72
|
+
Use the marker decorator on your test functions.
|
|
73
|
+
|
|
74
|
+
**Basic Dependency:**
|
|
75
|
+
`test_child` will only run if `test_parent` passes.
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import pytest
|
|
79
|
+
|
|
80
|
+
def test_parent():
|
|
81
|
+
assert True
|
|
82
|
+
|
|
83
|
+
@pytest.mark.depends_on(tests=["test_parent"])
|
|
84
|
+
def test_child():
|
|
85
|
+
assert True
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**Custom Status Dependency:**
|
|
89
|
+
`test_child` will run only if `test_parent` fails (useful for testing error handling or recovery).
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
import pytest
|
|
93
|
+
|
|
94
|
+
from pytest_depends_on.consts.status import Status
|
|
95
|
+
|
|
96
|
+
@pytest.mark.depends_on(tests=["test_parent"], status=Status.FAILED)
|
|
97
|
+
def test_child():
|
|
98
|
+
pass
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Soft Dependency:**
|
|
102
|
+
`test_child` will run even if `test_parent` hasn't executed yet (e.g., due to ordering).
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
import pytest
|
|
106
|
+
|
|
107
|
+
@pytest.mark.depends_on(tests=["test_parent"], allowed_not_run=True)
|
|
108
|
+
def test_child():
|
|
109
|
+
pass
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
-----
|
|
113
|
+
|
|
114
|
+
## 🤝 Contributing
|
|
115
|
+
|
|
116
|
+
If you have a helpful tool, pattern, or improvement to suggest:
|
|
117
|
+
Fork the repo <br>
|
|
118
|
+
Create a new branch <br>
|
|
119
|
+
Submit a pull request <br>
|
|
120
|
+
I welcome additions that promote clean, productive, and maintainable development. <br>
|
|
121
|
+
|
|
122
|
+
-----
|
|
123
|
+
|
|
124
|
+
## 🙏 Thanks
|
|
125
|
+
|
|
126
|
+
Thanks for exploring this repository\! <br>
|
|
127
|
+
Happy coding\! <br>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
pytest_depends_on/__init__.py
|
|
6
|
+
pytest_depends_on/depends_on.py
|
|
7
|
+
pytest_depends_on.egg-info/PKG-INFO
|
|
8
|
+
pytest_depends_on.egg-info/SOURCES.txt
|
|
9
|
+
pytest_depends_on.egg-info/dependency_links.txt
|
|
10
|
+
pytest_depends_on.egg-info/entry_points.txt
|
|
11
|
+
pytest_depends_on.egg-info/requires.txt
|
|
12
|
+
pytest_depends_on.egg-info/top_level.txt
|
|
13
|
+
pytest_depends_on/consts/__init__.py
|
|
14
|
+
pytest_depends_on/consts/status.py
|
|
15
|
+
tests/test_class.py
|
|
16
|
+
tests/test_multi_parent.py
|
|
17
|
+
tests/test_parent_failed.py
|
|
18
|
+
tests/test_parent_parametrize.py
|
|
19
|
+
tests/test_parent_passed.py
|
|
20
|
+
tests/test_parent_skip.py
|
|
21
|
+
tests/test_with_default_param.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pytest_depends_on
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from pytest_depends_on.consts.status import Status
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestA:
|
|
7
|
+
def test_parent_a(self) -> None:
|
|
8
|
+
with pytest.raises(AssertionError):
|
|
9
|
+
assert False
|
|
10
|
+
|
|
11
|
+
def test_parent_b(self) -> None:
|
|
12
|
+
assert True
|
|
13
|
+
|
|
14
|
+
def test_parent_c(self) -> None:
|
|
15
|
+
assert True
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@pytest.mark.skip(reason="skip")
|
|
19
|
+
class TestB:
|
|
20
|
+
def test_parent_b(self) -> None:
|
|
21
|
+
assert True
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class TestC:
|
|
25
|
+
@pytest.mark.depends_on(
|
|
26
|
+
tests=[
|
|
27
|
+
{"name": "TestA::test_parent_a", "status": Status.FAILED},
|
|
28
|
+
{"name": "TestA::test_parent_b", "status": Status.PASSED},
|
|
29
|
+
]
|
|
30
|
+
)
|
|
31
|
+
def test_child_a(self) -> None:
|
|
32
|
+
assert True
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class TestD:
|
|
36
|
+
@pytest.mark.depends_on(
|
|
37
|
+
tests=[
|
|
38
|
+
{"name": "TestA::test_parent_a", "status": Status.PASSED},
|
|
39
|
+
{"name": "TestA::test_parent_b", "status": Status.PASSED},
|
|
40
|
+
]
|
|
41
|
+
)
|
|
42
|
+
def test_child_b(self) -> None:
|
|
43
|
+
assert True
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class TestE:
|
|
47
|
+
@pytest.mark.depends_on(
|
|
48
|
+
tests=[
|
|
49
|
+
{"name": "TestA::test_parent_a", "status": Status.FAILED},
|
|
50
|
+
{"name": "TestB::test_parent_b", "status": Status.PASSED, "allowed_not_run": True},
|
|
51
|
+
]
|
|
52
|
+
)
|
|
53
|
+
def test_child_c(self) -> None:
|
|
54
|
+
assert True
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from pytest_depends_on.consts.status import Status
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_parent_a() -> None:
|
|
7
|
+
assert True
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_parent_b() -> None:
|
|
11
|
+
assert True
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@pytest.mark.skip(reason="skip")
|
|
15
|
+
def test_parent_c() -> None: # expected to status "SKIPPED"
|
|
16
|
+
assert True
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@pytest.mark.depends_on(
|
|
20
|
+
tests=[{"name": "test_parent_a", "status": Status.PASSED}, {"name": "test_parent_b", "status": Status.PASSED}],
|
|
21
|
+
status=Status.FAILED,
|
|
22
|
+
)
|
|
23
|
+
def test_child_a() -> None:
|
|
24
|
+
assert True
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.mark.depends_on(
|
|
28
|
+
tests=[{"name": "test_parent_a", "status": Status.PASSED}, {"name": "test_parent_b", "status": Status.FAILED}],
|
|
29
|
+
status=Status.FAILED,
|
|
30
|
+
)
|
|
31
|
+
def test_child_b() -> None: # expected to status "SKIPPED"
|
|
32
|
+
assert False
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.mark.depends_on(
|
|
36
|
+
tests=[{"name": "test_parent_a", "status": Status.PASSED}, {"name": "test_parent_c", "status": Status.PASSED}],
|
|
37
|
+
status=Status.FAILED,
|
|
38
|
+
)
|
|
39
|
+
def test_child_c() -> None: # expected to status "SKIPPED"
|
|
40
|
+
assert True
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@pytest.mark.depends_on(
|
|
44
|
+
tests=[{"name": "test_parent_a"}, {"name": "test_parent_c", "status": Status.PASSED, "allowed_not_run": True}],
|
|
45
|
+
status=Status.PASSED,
|
|
46
|
+
)
|
|
47
|
+
def test_child_d() -> None:
|
|
48
|
+
assert True
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from pytest_depends_on.consts.status import Status
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_parent() -> None:
|
|
7
|
+
with pytest.raises(AssertionError):
|
|
8
|
+
assert False
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.mark.depends_on(tests=["test_parent"], status=Status.PASSED)
|
|
12
|
+
def test_child_a() -> None: # expected to status "SKIPPED"
|
|
13
|
+
assert True
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.mark.depends_on(tests=["test_parent"], status=Status.FAILED)
|
|
17
|
+
def test_child_b() -> None:
|
|
18
|
+
assert True
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from pytest_depends_on.consts.status import Status
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.mark.parametrize(
|
|
7
|
+
"input_, expected",
|
|
8
|
+
[
|
|
9
|
+
(1, False),
|
|
10
|
+
(3, True),
|
|
11
|
+
(5, True),
|
|
12
|
+
],
|
|
13
|
+
)
|
|
14
|
+
def test_parent(input_: int, expected: bool) -> None: # expected to status "FAILED"
|
|
15
|
+
if expected:
|
|
16
|
+
assert expected
|
|
17
|
+
else:
|
|
18
|
+
with pytest.raises(AssertionError):
|
|
19
|
+
assert expected
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.mark.depends_on(tests=["test_parent[1-False]"], status=Status.PASSED)
|
|
23
|
+
def test_child_a() -> None: # expected to status "SKIPPED"
|
|
24
|
+
assert True
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.mark.depends_on(tests=["test_parent[1-False]"], status=Status.FAILED)
|
|
28
|
+
def test_child_b() -> None:
|
|
29
|
+
assert True
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@pytest.mark.depends_on(tests=["test_parent[5-True]"], status=Status.PASSED)
|
|
33
|
+
def test_child_c() -> None:
|
|
34
|
+
assert True
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pytest.mark.depends_on(tests=["test_parent[5-True]"], status=Status.FAILED)
|
|
38
|
+
def test_child_d() -> None: # expected to status "SKIPPED"
|
|
39
|
+
assert True
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@pytest.mark.depends_on(tests=["test_parent[3-True]", "test_parent[5-True]"], status=Status.PASSED)
|
|
43
|
+
def test_child_e() -> None:
|
|
44
|
+
assert True
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@pytest.mark.depends_on(tests=["test_parent[3-True]", "test_parent[5-True]"], status=Status.FAILED)
|
|
48
|
+
def test_child_f() -> None: # expected to status "SKIPPED"
|
|
49
|
+
assert True
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from pytest_depends_on.consts.status import Status
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_parent() -> None:
|
|
7
|
+
assert True
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@pytest.mark.depends_on(tests=["test_parent"], status=Status.PASSED)
|
|
11
|
+
def test_child_a() -> None:
|
|
12
|
+
assert True
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@pytest.mark.depends_on(tests=["test_parent"], status=Status.FAILED)
|
|
16
|
+
def test_child_b() -> None: # expected to status "SKIPPED"
|
|
17
|
+
assert True
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from pytest_depends_on.consts.status import Status
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.mark.skip(reason="skip")
|
|
7
|
+
def test_parent() -> None: # expected to status "SKIPPED"
|
|
8
|
+
assert True
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.mark.depends_on(tests=["test_parent"], status=Status.PASSED)
|
|
12
|
+
def test_child_a() -> None: # expected to status "SKIPPED"
|
|
13
|
+
assert True
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.mark.depends_on(tests=["test_parent"], status=Status.PASSED, allowed_not_run=True)
|
|
17
|
+
def test_child_b() -> None:
|
|
18
|
+
assert True
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from pytest_depends_on.consts.status import Status
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_parent_a() -> None:
|
|
7
|
+
assert True
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_parent_b() -> None:
|
|
11
|
+
with pytest.raises(AssertionError):
|
|
12
|
+
assert False
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_parent_c() -> None:
|
|
16
|
+
assert True
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@pytest.mark.depends_on(
|
|
20
|
+
tests=[{"name": "test_parent_a"}, {"name": "test_parent_b", "status": Status.FAILED}], status=Status.PASSED
|
|
21
|
+
)
|
|
22
|
+
def test_child_a() -> None:
|
|
23
|
+
assert True
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@pytest.mark.depends_on(
|
|
27
|
+
tests=[{"name": "test_parent_a"}, {"name": "test_parent_b", "status": Status.FAILED}], status=Status.FAILED
|
|
28
|
+
)
|
|
29
|
+
def test_child_b() -> None: # expected to status "SKIPPED"
|
|
30
|
+
assert True
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.mark.depends_on(tests=[{"name": "test_parent_a"}, {"name": "test_parent_b"}], status=Status.PASSED)
|
|
34
|
+
def test_child_c() -> None: # expected to status "SKIPPED"
|
|
35
|
+
assert True
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pytest.mark.depends_on(tests=[{"name": "test_parent_a"}, {"name": "test_parent_c"}], status=Status.PASSED)
|
|
39
|
+
def test_child_c() -> None: # pylint: disable=E0102
|
|
40
|
+
assert True
|