Skip to content

Commit

Permalink
test: config mutmut
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Jul 31, 2023
1 parent 6c9450e commit 69122f8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
25 changes: 24 additions & 1 deletion mutmut_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
import os.path


def pre_mutation(context):
line = context.current_source_line.strip()
if line.strip().startswith(("assert False", "@overload", "= TypeVar")):
if line.startswith(("assert False", "@overload")):
context.skip = True

if "= TypeVar" in line:
context.skip = True

return
"""Extract the coverage contexts if possible and only run the tests
matching this data."""
if not context.config.coverage_data:
# mutmut was run without ``--use-coverage``
return
fname = os.path.abspath(context.filename)
contexts_for_file = context.config.coverage_data.get(fname, {})
contexts_for_line = contexts_for_file.get(context.current_line_index, [])
print(line)
print(contexts_for_line)

context.config.test_command += " ".join(
repr(arg) for arg in contexts_for_line if arg
)
print(context.config.test_command)
16 changes: 16 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,20 @@ def docs(session):
def mutmut(session):
session.install("poetry")
session.run("poetry", "install", "--with=dev")

coverage = False

if coverage:
session.run("coverage", "erase")

session.env["COVERAGE_PROCESS_START"] = str(
Path(__file__).parent / "pyproject.toml"
)
session.env["TOP"] = str(Path(__file__).parent)
session.run("pytest", "--doctest-modules", "inline_snapshot", "tests")
session.run("coverage", "combine")

session.run("mutmut", "run", *session.posargs)

if coverage:
session.run("coverage", "erase")
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ version_files = [
]
version_provider = "poetry"

[tool.coverage.html]
show_contexts = true

[tool.coverage.report]
exclude_lines = ["pragma: no cover", "assert False", "raise NotImplemented", "\\.\\.\\."]

Expand Down
19 changes: 19 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
pytest_plugins = "pytester"

import pytest
import coverage

import os

ctx_key = "COVERAGE_CONTEXT"


@pytest.fixture(autouse=True)
def coverage_context(request):
ctx = request.node.nodeid
coverage.Coverage.current().switch_context(request.node.nodeid)

os.environ[ctx_key] = ctx

yield

coverage.Coverage.current().switch_context("")

0 comments on commit 69122f8

Please sign in to comment.