Leave out a failing test file by its absolute path, since pytest 9.2 under mutmut 3.8.1 reports nodeids as mutants/<path>
This commit is contained in:
@@ -12,7 +12,7 @@ from mutate_changes.changed_lines import added_lines, runs, tool_for
|
||||
from failure import Failure
|
||||
from mutate_changes.mutmut_mutants import function_keys, mutant_globs, mutated_line, named, statuses
|
||||
from test_env import isolated_env
|
||||
from mutate_changes.mutmut_setup import left_out, mutmut_config
|
||||
from mutate_changes.mutmut_setup import leaving_out, left_out, mutmut_config
|
||||
|
||||
TOOL = pathlib.Path(__file__).resolve().parents[1] / "mutate-changes"
|
||||
SOURCE = "def double(n):\n\treturn n * 2\n\n\nclass Pt:\n\tdef moved(self, by=1):\n\t\treturn self.x + by\n"
|
||||
@@ -95,13 +95,17 @@ class MutmutSetup(unittest.TestCase):
|
||||
FAILED fake.py::t - this line is a test's own output, above the summary
|
||||
ERROR root:x.py:3 a log line
|
||||
=========================== short test summary info ============================
|
||||
FAILED repo_checks/test_repo_checks.py::Repo::test_a - AssertionError: x - y
|
||||
ERROR larv_review/test_larv_review.py - FileNotFoundError: SKILL.md
|
||||
FAILED mutants/repo_checks/test_repo_checks.py::Repo::test_a - AssertionError: x - y
|
||||
ERROR mutants/larv_review/test_larv_review.py - FileNotFoundError: SKILL.md
|
||||
ERROR test_io.py
|
||||
FAILED a/test_b.py::T::test_c
|
||||
2 failed, 1 error in 3.10s
|
||||
2 failed, 2 errors in 3.10s
|
||||
failed to collect stats. runner returned 1
|
||||
""")
|
||||
self.assertEqual(left_out(output), ["--deselect=repo_checks/test_repo_checks.py::Repo::test_a", "--ignore=larv_review/test_larv_review.py", "--deselect=a/test_b.py::T::test_c"])
|
||||
self.assertEqual(left_out(output), ["mutants/repo_checks/test_repo_checks.py::Repo::test_a", "mutants/larv_review/test_larv_review.py", "test_io.py", "a/test_b.py::T::test_c"])
|
||||
|
||||
def test_a_test_is_deselected_by_its_nodeid_and_a_file_ignored_by_its_path_in_mutants(self):
|
||||
self.assertEqual(leaving_out(["mutants/t/test_a.py::T::test_b", "mutants/t/test_c.py", "t/test_d.py"], "/copy"), ["--deselect=mutants/t/test_a.py::T::test_b", "--ignore=/copy/mutants/t/test_c.py", "--ignore=/copy/mutants/t/test_d.py"])
|
||||
|
||||
def test_left_out_is_empty_without_a_summary(self):
|
||||
self.assertEqual(left_out("failed to collect stats. runner returned 1\n"), [])
|
||||
@@ -141,15 +145,15 @@ class MutmutMutants(unittest.TestCase):
|
||||
|
||||
# Stands in for mutmut, run through --prefix as `python3 <this> <log> <mode> mutmut ...` in the scratch copy. It logs each call with
|
||||
# the setup.cfg it finds there, then writes a mutants/ copy and prints results, both shaped like mutmut 3's.
|
||||
FAKE_MUTMUT = r"""import pathlib, sys
|
||||
FAKE_MUTMUT = r"""import os, pathlib, sys
|
||||
log, mode, args = pathlib.Path(sys.argv[1]), sys.argv[2], sys.argv[3:]
|
||||
config = pathlib.Path("setup.cfg").read_text()
|
||||
with log.open("a") as written:
|
||||
written.write(" ".join(args) + "\n" + config + "---\n")
|
||||
if args[:2] == ["mutmut", "results"]:
|
||||
print(" calc.x_triple__mutmut_1: survived\n calc.x_triple__mutmut_2: killed\n calc.x_double__mutmut_1: survived")
|
||||
elif mode == "fails-once" and "--deselect=test_calc.py::Calc::test_slow" not in config:
|
||||
print("==== short test summary info ====\nFAILED test_calc.py::Calc::test_slow - boom\nfailed to collect stats. runner returned 1")
|
||||
elif mode == "fails-once" and not ("--deselect=mutants/test_calc.py::Calc::test_slow" in config and f"--ignore={os.getcwd()}/mutants/test_io.py" in config):
|
||||
print("==== short test summary info ====\nFAILED mutants/test_calc.py::Calc::test_slow - boom\nERROR mutants/test_io.py - FileNotFoundError\nfailed to collect stats. runner returned 1")
|
||||
sys.exit(1)
|
||||
else:
|
||||
pathlib.Path("mutants").mkdir(exist_ok=True)
|
||||
@@ -203,7 +207,7 @@ class MutateChangesTool(unittest.TestCase):
|
||||
def test_leaves_out_the_tests_that_fail_before_any_mutant_and_names_them(self):
|
||||
ran = self.run_tool(*self.faked("fails-once"))
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
self.assertEqual(ran.stdout.splitlines()[:2], ["mutmut in pkg: 2 mutants on changed lines, 1 not killed. Left out tests in test_calc.py that fail without a mutant.", "pkg/calc.py:6: survived: return n / 3"])
|
||||
self.assertEqual(ran.stdout.splitlines()[:2], ["mutmut in pkg: 2 mutants on changed lines, 1 not killed. Left out tests in test_calc.py, test_io.py that fail without a mutant.", "pkg/calc.py:6: survived: return n / 3"])
|
||||
first, second = self.log.read_text().split("---\n")[:2]
|
||||
self.assertIn("--maxfail=0", first)
|
||||
self.assertNotIn("--maxfail=0", second)
|
||||
|
||||
Reference in New Issue
Block a user