Change how we run pytest, to increase coverage calculation

This commit is contained in:
gabrii
2025-09-18 12:27:02 +02:00
parent 876f539ebb
commit 6e7a0b66f4
2 changed files with 14 additions and 14 deletions
+2 -4
View File
@@ -27,9 +27,7 @@ TEST_PATH = os.path.join(PROJECT_ROOT, "tests")
)
def test(coverage, filter):
"""Run the tests."""
import pytest
args = [TEST_PATH, "--verbose"]
args = ["pytest", TEST_PATH, "--verbose"]
if coverage:
args.append("--cov=app")
args.append("--cov-branch")
@@ -38,7 +36,7 @@ def test(coverage, filter):
args.append("--cov-report=term")
if filter:
args.extend(["-k", filter])
rv = pytest.main(args=args)
rv = call(args)
exit(rv)
+12 -10
View File
@@ -6,14 +6,17 @@ import app.commands as commands
def test_test_command_calls_pytest_with_coverage_and_exits(mocker):
"""Invoke `test` command with defaults and ensure pytest args include coverage."""
fake_main = mocker.patch("pytest.main", return_value=0)
"""Invoke `test` command with defaults and ensure subprocess call args include coverage."""
mock_call = mocker.patch("app.commands.call", return_value=0)
runner = CliRunner()
result = runner.invoke(commands.test)
assert result.exit_code == 0
expected = [
mock_call.assert_called_once()
cmdline = mock_call.call_args[0][0]
assert cmdline == [
"pytest",
commands.TEST_PATH,
"--verbose",
"--cov=app",
@@ -22,26 +25,25 @@ def test_test_command_calls_pytest_with_coverage_and_exits(mocker):
"--cov-report=html",
"--cov-report=term",
]
fake_main.assert_called_once()
assert fake_main.call_args.kwargs["args"] == expected
def test_test_command_no_coverage_and_filter(mocker):
"""Invoke `test` with no coverage and a filter; ensure pytest args are correct."""
fake_main = mocker.patch("pytest.main", return_value=5)
"""Invoke `test` with no coverage and a filter; ensure subprocess call args are correct."""
mock_call = mocker.patch("app.commands.call", return_value=5)
runner = CliRunner()
result = runner.invoke(commands.test, ["-C", "-k", "unit and not e2e"])
assert result.exit_code == 5
expected = [
mock_call.assert_called_once()
cmdline = mock_call.call_args[0][0]
assert cmdline == [
"pytest",
commands.TEST_PATH,
"--verbose",
"-k",
"unit and not e2e",
]
fake_main.assert_called_once()
assert fake_main.call_args.kwargs["args"] == expected
def test_lint_command_invokes_tools_with_expected_order(mocker):