diff --git a/tests/test_cli_invocation.py b/tests/test_cli_invocation.py index 10fb9ba..3afa0a4 100644 --- a/tests/test_cli_invocation.py +++ b/tests/test_cli_invocation.py @@ -150,7 +150,6 @@ def test_implicit_help(self, mocked_runner: MockedRunner) -> None: assert result.exception is None, report_traceback(result.exception) assert result.exit_code == 0 - # TODO: Collect test coverage stats for this entry point invocation @requires_venv("Entry point test") def test_entry_point_help_raw(self) -> None: expected_entry_point = Path(sys.executable).parent / "venvstacks" @@ -169,7 +168,6 @@ def test_entry_point_help_raw(self) -> None: assert result.returncode == 0 assert result.stdout is not None - # TODO: Collect test coverage stats for this entry point invocation @requires_venv("Entry point test") def test_entry_point_help(self) -> None: expected_entry_point = Path(sys.executable).parent / "venvstacks" @@ -188,6 +186,24 @@ def test_entry_point_help(self) -> None: assert result.returncode == 0 assert result.stdout is not None + def test_module_execution(self) -> None: + # TODO: `coverage.py` isn't picking this up as executing `venvstacks/__main__.py` + # (even an indirect invocation via the runpy module doesn't get detected) + command = [sys.executable, "-m", "venvstacks", "--help"] + result = run_python_command_unchecked( + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + if result.stdout is not None: + # Usage message should suggest indirect execution + assert "Usage: python -m venvstacks [" in result.stdout + # Top-level callback docstring is used as the overall CLI help text + cli_help = cli.handle_app_options.__doc__ + assert cli_help is not None + assert cli_help.strip() in result.stdout + # Check operation result last to ensure test results are as informative as possible + assert result.returncode == 0 + assert result.stdout is not None + EXPECTED_USAGE_PREFIX = "Usage: python -m venvstacks " EXPECTED_SUBCOMMANDS = ["lock", "build", "local-export", "publish"] diff --git a/tox.ini b/tox.ini index 2b42a3a..f3c42cc 100644 --- a/tox.ini +++ b/tox.ini @@ -10,6 +10,9 @@ labels = static = lint,typecheck [testenv] +# Multi-env performance tweak based on https://hynek.me/articles/turbo-charge-tox/ +package = wheel +wheel_build_env = .pkg groups = dev allowlist_externals = pytest passenv = @@ -19,28 +22,24 @@ commands = pytest {posargs:-m "not slow"} tests/ [testenv:coverage] -groups = dev +# Subprocess coverage based on https://hynek.me/articles/turbo-charge-tox/ allowlist_externals = coverage -passenv = - CI - VENVSTACKS_* +set_env = COVERAGE_PROCESS_START={toxinidir}/pyproject.toml +commands_pre = python -c 'import pathlib; pathlib.Path("{env_site_packages_dir}/cov.pth").write_text("import coverage; coverage.process_startup()")' commands = coverage run --parallel -m pytest {posargs} tests/ [testenv:format] -groups = dev allowlist_externals = ruff commands = ruff format {posargs} src/ tests/ misc/ [testenv:lint] -groups = dev allowlist_externals = ruff commands = ruff check --exclude 'tests/sample_project' {posargs} src/ tests/ misc/ [testenv:typecheck] -groups = dev allowlist_externals = mypy commands = mypy --strict --exclude 'tests/sample_project' {posargs} src/ tests/ misc/