diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..17ffeee --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,25 @@ +from pathlib import Path +from subprocess import check_call + +import pytest + +NETCORE_VERSION = "net10.0" + + +@pytest.fixture(scope="session") +def example_netstandard(tmp_path_factory: pytest.TempPathFactory) -> Path: + return build_example(tmp_path_factory, "netstandard2.0") + + +@pytest.fixture(scope="session") +def example_netcore(tmp_path_factory: pytest.TempPathFactory) -> Path: + return build_example(tmp_path_factory, NETCORE_VERSION) + + +def build_example(tmp_path_factory: pytest.TempPathFactory, framework: str) -> Path: + out = tmp_path_factory.mktemp(f"example-{framework}") + proj_path = Path(__file__).parent.parent / "example" / "example.csproj" + + _ = check_call(["dotnet", "build", str(proj_path), "-o", str(out), "-f", framework]) + + return out diff --git a/tests/test_common.py b/tests/test_common.py index 4c3e1e4..263cb16 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -1,31 +1,9 @@ import shutil import sys from pathlib import Path -from subprocess import check_call import pytest -NETCORE_VERSION = "net10.0" - - -@pytest.fixture(scope="session") -def example_netstandard(tmp_path_factory: pytest.TempPathFactory) -> Path: - return build_example(tmp_path_factory, "netstandard2.0") - - -@pytest.fixture(scope="session") -def example_netcore(tmp_path_factory: pytest.TempPathFactory) -> Path: - return build_example(tmp_path_factory, NETCORE_VERSION) - - -def build_example(tmp_path_factory: pytest.TempPathFactory, framework: str) -> Path: - out = tmp_path_factory.mktemp(f"example-{framework}") - proj_path = Path(__file__).parent.parent / "example" / "example.csproj" - - _ = check_call(["dotnet", "build", str(proj_path), "-o", str(out), "-f", framework]) - - return out - def test_mono(example_netstandard: Path): from clr_loader import get_mono @@ -112,7 +90,7 @@ def test_coreclr_properties(example_netcore: Path): run_in_subprocess( _do_test_coreclr_autogenerated_runtimeconfig, example_netcore, - properties=dict(APP_CONTEXT_BASE_DIRECTORY=str(example_netcore)), + APP_CONTEXT_BASE_DIRECTORY=str(example_netcore), ) @@ -177,4 +155,9 @@ def run_in_subprocess(func, *args, **kwargs): p = get_context("spawn").Process(target=func, args=args, kwargs=kwargs) p.start() p.join() - p.close() + try: + assert p.exitcode == 0, ( + f"Subprocess {func.__name__!r} failed with exit code {p.exitcode}" + ) + finally: + p.close()