ci / Formatting (pull_request) Successful in 24s
ci / Compose (pull_request) Successful in 16s
ci / Workflows (pull_request) Successful in 9s
ci / Shell (pull_request) Successful in 18s
ci / Python and tests (pull_request) Successful in 11s
ci / YAML (pull_request) Successful in 11s
ci / Dockerfiles (pull_request) Successful in 7s
ci / Kubernetes (pull_request) Successful in 8s
ci / image-plan (pull_request) Skipped
ci / Image (${{ matrix.name }}) (pull_request) Skipped
ci / build (pull_request) Skipped
38 lines
1.6 KiB
Python
38 lines
1.6 KiB
Python
"""Run the real unit tests with external CI files and detect leaked writes."""
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
from ci_test_case import IsolatedCITestCase
|
|
|
|
|
|
class CIOutputIsolationTests(IsolatedCITestCase):
|
|
def test_unit_suite_preserves_external_ci_files(self):
|
|
tests = Path(__file__).resolve().parent
|
|
modules = sorted(p.stem for p in tests.glob('test_*.py') if p.name != Path(__file__).name)
|
|
with tempfile.TemporaryDirectory() as scratch:
|
|
environment = os.environ.copy()
|
|
environment['PYTHONPATH'] = str(tests) + os.pathsep + environment.get('PYTHONPATH', '')
|
|
expected = {}
|
|
for variable in ('GITHUB_STEP_SUMMARY', 'GITHUB_OUTPUT'):
|
|
path = Path(scratch) / variable
|
|
content = f'external {variable}\n'
|
|
path.write_text(content)
|
|
environment[variable] = str(path)
|
|
expected[path] = content
|
|
result = subprocess.run( # noqa: S603 -- Run local test modules with the current Python interpreter.
|
|
[sys.executable, '-m', 'unittest', *modules, '-q'],
|
|
cwd=tests.parent,
|
|
env=environment,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
timeout=60,
|
|
)
|
|
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
|
for path, content in expected.items():
|
|
self.assertEqual(path.read_text(), content, f'Unit tests wrote to external {path.name}')
|