Change how we run pytest, to increase coverage calculation
This commit is contained in:
+2
-4
@@ -27,9 +27,7 @@ TEST_PATH = os.path.join(PROJECT_ROOT, "tests")
|
|||||||
)
|
)
|
||||||
def test(coverage, filter):
|
def test(coverage, filter):
|
||||||
"""Run the tests."""
|
"""Run the tests."""
|
||||||
import pytest
|
args = ["pytest", TEST_PATH, "--verbose"]
|
||||||
|
|
||||||
args = [TEST_PATH, "--verbose"]
|
|
||||||
if coverage:
|
if coverage:
|
||||||
args.append("--cov=app")
|
args.append("--cov=app")
|
||||||
args.append("--cov-branch")
|
args.append("--cov-branch")
|
||||||
@@ -38,7 +36,7 @@ def test(coverage, filter):
|
|||||||
args.append("--cov-report=term")
|
args.append("--cov-report=term")
|
||||||
if filter:
|
if filter:
|
||||||
args.extend(["-k", filter])
|
args.extend(["-k", filter])
|
||||||
rv = pytest.main(args=args)
|
rv = call(args)
|
||||||
exit(rv)
|
exit(rv)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+12
-10
@@ -6,14 +6,17 @@ import app.commands as commands
|
|||||||
|
|
||||||
|
|
||||||
def test_test_command_calls_pytest_with_coverage_and_exits(mocker):
|
def test_test_command_calls_pytest_with_coverage_and_exits(mocker):
|
||||||
"""Invoke `test` command with defaults and ensure pytest args include coverage."""
|
"""Invoke `test` command with defaults and ensure subprocess call args include coverage."""
|
||||||
fake_main = mocker.patch("pytest.main", return_value=0)
|
mock_call = mocker.patch("app.commands.call", return_value=0)
|
||||||
|
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
result = runner.invoke(commands.test)
|
result = runner.invoke(commands.test)
|
||||||
|
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
expected = [
|
mock_call.assert_called_once()
|
||||||
|
cmdline = mock_call.call_args[0][0]
|
||||||
|
assert cmdline == [
|
||||||
|
"pytest",
|
||||||
commands.TEST_PATH,
|
commands.TEST_PATH,
|
||||||
"--verbose",
|
"--verbose",
|
||||||
"--cov=app",
|
"--cov=app",
|
||||||
@@ -22,26 +25,25 @@ def test_test_command_calls_pytest_with_coverage_and_exits(mocker):
|
|||||||
"--cov-report=html",
|
"--cov-report=html",
|
||||||
"--cov-report=term",
|
"--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):
|
def test_test_command_no_coverage_and_filter(mocker):
|
||||||
"""Invoke `test` with no coverage and a filter; ensure pytest args are correct."""
|
"""Invoke `test` with no coverage and a filter; ensure subprocess call args are correct."""
|
||||||
fake_main = mocker.patch("pytest.main", return_value=5)
|
mock_call = mocker.patch("app.commands.call", return_value=5)
|
||||||
|
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
result = runner.invoke(commands.test, ["-C", "-k", "unit and not e2e"])
|
result = runner.invoke(commands.test, ["-C", "-k", "unit and not e2e"])
|
||||||
|
|
||||||
assert result.exit_code == 5
|
assert result.exit_code == 5
|
||||||
expected = [
|
mock_call.assert_called_once()
|
||||||
|
cmdline = mock_call.call_args[0][0]
|
||||||
|
assert cmdline == [
|
||||||
|
"pytest",
|
||||||
commands.TEST_PATH,
|
commands.TEST_PATH,
|
||||||
"--verbose",
|
"--verbose",
|
||||||
"-k",
|
"-k",
|
||||||
"unit and not e2e",
|
"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):
|
def test_lint_command_invokes_tools_with_expected_order(mocker):
|
||||||
|
|||||||
Reference in New Issue
Block a user