MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_linematcher_no_matching

Function test_linematcher_no_matching

testing/test_pytester.py:559–604  ·  view source on GitHub ↗
(function: str)

Source from the content-addressed store, hash-verified

557
558@pytest.mark.parametrize("function", ["no_fnmatch_line", "no_re_match_line"])
559def test_linematcher_no_matching(function: str) -> None:
560 if function == "no_fnmatch_line":
561 good_pattern = "*.py OK*"
562 bad_pattern = "*X.py OK*"
563 else:
564 assert function == "no_re_match_line"
565 good_pattern = r".*py OK"
566 bad_pattern = r".*Xpy OK"
567
568 lm = LineMatcher(
569 [
570 "cachedir: .pytest_cache",
571 "collecting ... collected 1 item",
572 "",
573 "show_fixtures_per_test.py OK",
574 "=== elapsed 1s ===",
575 ]
576 )
577
578 # check the function twice to ensure we don't accumulate the internal buffer
579 for i in range(2):
580 with pytest.raises(pytest.fail.Exception) as e:
581 func = getattr(lm, function)
582 func(good_pattern)
583 obtained = str(e.value).splitlines()
584 if function == "no_fnmatch_line":
585 assert obtained == [
586 f"nomatch: '{good_pattern}'",
587 " and: 'cachedir: .pytest_cache'",
588 " and: 'collecting ... collected 1 item'",
589 " and: ''",
590 f"fnmatch: '{good_pattern}'",
591 " with: 'show_fixtures_per_test.py OK'",
592 ]
593 else:
594 assert obtained == [
595 f" nomatch: '{good_pattern}'",
596 " and: 'cachedir: .pytest_cache'",
597 " and: 'collecting ... collected 1 item'",
598 " and: ''",
599 f"re.match: '{good_pattern}'",
600 " with: 'show_fixtures_per_test.py OK'",
601 ]
602
603 func = getattr(lm, function)
604 func(bad_pattern) # bad pattern does not match any line: passes
605
606
607def test_linematcher_no_matching_after_match() -> None:

Callers

nothing calls this directly

Calls 2

LineMatcherClass · 0.90
funcFunction · 0.70

Tested by

no test coverage detected