feat(testing): init pytest fixtures
current_test fixture allows to retrieve the current test context, that is exposed through the shell environment
This commit is contained in:
parent
c579ddd022
commit
644beb8696
6 changed files with 51 additions and 2 deletions
3
Makefile
3
Makefile
|
|
@ -21,6 +21,9 @@ test-reports: test-reports/unit test-reports/static
|
|||
test-reports/unit:
|
||||
python3 -m pipenv run -v test-unit
|
||||
|
||||
test-reports/integration:
|
||||
python3 -m pipenv run -v test-integration
|
||||
|
||||
test-reports/static:
|
||||
python3 -m pipenv run -v test-static
|
||||
|
||||
|
|
|
|||
1
Pipfile
1
Pipfile
|
|
@ -17,3 +17,4 @@ python_version = "3.11"
|
|||
"build" = "python3 -m build"
|
||||
"test-static" = "tox run -m static"
|
||||
"test-unit" = "tox run -m unit"
|
||||
"test-integration" = "tox run -m integration"
|
||||
|
|
|
|||
14
src/byteb4rb1e/utils/testing/pytest/fixtures.py
Normal file
14
src/byteb4rb1e/utils/testing/pytest/fixtures.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
from typing import Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def current_test() -> Tuple[Path, str]:
|
||||
"""
|
||||
"""
|
||||
suite_path, case_name = os.getenv('PYTEST_CURRENT_TEST').split('::', 1)
|
||||
case_name = case_name.split(' ', 1)[0]
|
||||
return Path(suite_path).resolve(), case_name
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.pytest
|
||||
|
||||
from byteb4rb1e.utils.testing.pytest.fixtures import current_test
|
||||
|
||||
|
||||
def test_current_test(current_test):
|
||||
"""
|
||||
"""
|
||||
suite_path, case_name = current_test
|
||||
|
||||
assert str(Path(__file__)) == str(suite_path)
|
||||
assert case_name == "test_current_test"
|
||||
5
tests/integration/conftest.py
Normal file
5
tests/integration/conftest.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def pytest_configure(config):
|
||||
# register an additional marker
|
||||
config.addinivalue_line(
|
||||
"markers", "pytest: test pytest integration"
|
||||
)
|
||||
14
tox.ini
14
tox.ini
|
|
@ -2,7 +2,8 @@
|
|||
requires =
|
||||
tox>=4.19
|
||||
env_list =
|
||||
py3{8-12}-{unit}
|
||||
unit-py3{9-13}
|
||||
integration-py3{9-13}-pytest8
|
||||
lint
|
||||
format
|
||||
|
||||
|
|
@ -34,7 +35,7 @@ deps =
|
|||
commands =
|
||||
black --check src tests
|
||||
|
||||
[testenv:py3{9-13}-unit]
|
||||
[testenv:unit-py3{9-13}]
|
||||
description = run type check on code base
|
||||
labels = unit
|
||||
deps =
|
||||
|
|
@ -42,3 +43,12 @@ deps =
|
|||
pytest
|
||||
commands =
|
||||
pytest tests/unit --junitxml=test-reports/{env_name}.xml
|
||||
|
||||
[testenv:integration-py3{9-13}-pytest8]
|
||||
description = run pytest integration tests
|
||||
labels = integration
|
||||
deps =
|
||||
{[testenv]deps}
|
||||
pytest8: pytest>=8.0,<=9.0
|
||||
commands =
|
||||
pytest tests/integration -m pytest --junitxml=test-reports/{env_name}.xml
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue