chore: move testing utils out of utils
This commit is contained in:
parent
55ec6323bb
commit
9abfabde00
7 changed files with 9 additions and 9 deletions
33
tests/integration/byteb4rb1e/testing/pytest/test_.py
Normal file
33
tests/integration/byteb4rb1e/testing/pytest/test_.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.pytest
|
||||
|
||||
from byteb4rb1e.testing.pytest import get_current_test
|
||||
from byteb4rb1e.testing.pytest.decorators import run_in_subprocess_once
|
||||
|
||||
|
||||
class Test_get_current_test:
|
||||
"""
|
||||
"""
|
||||
|
||||
def test_default(self):
|
||||
"""
|
||||
"""
|
||||
os.environ['PYTEST_CURRENT_TEST'] = 'foo::bar (something)'
|
||||
|
||||
result = get_current_test()
|
||||
|
||||
assert isinstance(result[0], Path)
|
||||
assert str(result[0].name) == 'foo'
|
||||
|
||||
assert result[1] == 'bar'
|
||||
|
||||
def test_invalid(self):
|
||||
"""
|
||||
"""
|
||||
del os.environ['PYTEST_CURRENT_TEST']
|
||||
with pytest.raises(RuntimeError):
|
||||
get_current_test()
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.pytest
|
||||
|
||||
from byteb4rb1e.testing.pytest.decorators import run_in_subprocess_once
|
||||
|
||||
|
||||
@run_in_subprocess_once()
|
||||
def test_run_in_subprocess_once(tmp_path):
|
||||
marker = tmp_path / "executed_in_subprocess.txt"
|
||||
|
||||
if marker.exists():
|
||||
raise AssertionError("Marker file exists before test logic ran (shouldn't happen in parent process)")
|
||||
|
||||
# Create proof of execution
|
||||
marker.write_text("Subprocess was here.")
|
||||
|
||||
# Now assert it
|
||||
assert marker.exists()
|
||||
33
tests/integration/byteb4rb1e/testing/pytest/test_fixtures.py
Normal file
33
tests/integration/byteb4rb1e/testing/pytest/test_fixtures.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from pathlib import Path
|
||||
import importlib.resources
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.pytest
|
||||
|
||||
from byteb4rb1e.testing.pytest.decorators import run_in_subprocess_once
|
||||
from byteb4rb1e.testing.pytest.fixtures import current_test, mock_pkg
|
||||
|
||||
|
||||
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"
|
||||
|
||||
|
||||
@run_in_subprocess_once()
|
||||
def test_mock_pkg(mock_pkg):
|
||||
"""
|
||||
"""
|
||||
dummy_data = 'Hello'
|
||||
|
||||
mock_pkg('foobarpkg', {
|
||||
'data.txt': dummy_data
|
||||
})
|
||||
|
||||
result = next(importlib.resources.files('foobarpkg').glob('data.txt')).read_text()
|
||||
|
||||
assert result == dummy_data
|
||||
Loading…
Add table
Add a link
Reference in a new issue