feat(testing.pytest): add subprocess decorator

This commit is contained in:
Tiara Rodney 2025-06-20 23:16:16 +02:00
parent 1ea3b3a24d
commit 43cdf21d4b
No known key found for this signature in database
GPG key ID: 5F43FAB4FBE5B5EB
6 changed files with 122 additions and 3 deletions

View file

@ -0,0 +1,33 @@
import os
from pathlib import Path
import pytest
pytestmark = pytest.mark.pytest
from byteb4rb1e.utils.testing.pytest import get_current_test
from byteb4rb1e.utils.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()

View file

@ -0,0 +1,21 @@
from pathlib import Path
import pytest
pytestmark = pytest.mark.pytest
from byteb4rb1e.utils.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()

View file

@ -1,5 +1,8 @@
import pytest
from byteb4rb1e.utils.urllib.request import PkgHandler
class TestPkgHandler:
"""
"""
@ -7,3 +10,4 @@ class TestPkgHandler:
"""
"""
pass