diff options
author | Daniel Hahler <git@thequod.de> | 2019-10-22 01:33:43 +0200 |
---|---|---|
committer | Daniel Hahler <git@thequod.de> | 2019-10-24 23:20:12 +0200 |
commit | 8ef4287bf0b2a0a6ff7e612ed48ba3e781f570d4 (patch) | |
tree | a7df40aea808fd5c587c5fce859bb5378d1f6ad0 /testing/test_pytester.py | |
parent | 978c7ae1b72e410be6d2db25cee2817e91c2d4e4 (diff) | |
download | pytest-8ef4287bf0b2a0a6ff7e612ed48ba3e781f570d4.tar.gz |
pytester: align prefixes
This is important for using another match_nickname, e.g. "re.match".
TODO:
- [ ] changelog
- [ ] test
Diffstat (limited to 'testing/test_pytester.py')
-rw-r--r-- | testing/test_pytester.py | 59 |
1 files changed, 44 insertions, 15 deletions
diff --git a/testing/test_pytester.py b/testing/test_pytester.py index f8b0896c5..63710143a 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -457,16 +457,39 @@ def test_linematcher_with_nonlist(): assert lm._getlines(set()) == set() +def test_linematcher_match_failure(): + lm = LineMatcher(["foo", "foo", "bar"]) + with pytest.raises(pytest.fail.Exception) as e: + lm.fnmatch_lines(["foo", "f*", "baz"]) + assert e.value.msg.splitlines() == [ + "exact match: 'foo'", + "fnmatch: 'f*'", + " with: 'foo'", + "nomatch: 'baz'", + " and: 'bar'", + "remains unmatched: 'baz'", + ] + + lm = LineMatcher(["foo", "foo", "bar"]) + with pytest.raises(pytest.fail.Exception) as e: + lm.re_match_lines(["foo", "^f.*", "baz"]) + assert e.value.msg.splitlines() == [ + "exact match: 'foo'", + "re.match: '^f.*'", + " with: 'foo'", + " nomatch: 'baz'", + " and: 'bar'", + "remains unmatched: 'baz'", + ] + + @pytest.mark.parametrize("function", ["no_fnmatch_line", "no_re_match_line"]) def test_no_matching(function): - """""" if function == "no_fnmatch_line": - match_func_name = "fnmatch" good_pattern = "*.py OK*" bad_pattern = "*X.py OK*" else: assert function == "no_re_match_line" - match_func_name = "re.match" good_pattern = r".*py OK" bad_pattern = r".*Xpy OK" @@ -480,24 +503,30 @@ def test_no_matching(function): ] ) - def check_failure_lines(lines): - expected = [ - "nomatch: '{}'".format(good_pattern), - " and: 'cachedir: .pytest_cache'", - " and: 'collecting ... collected 1 item'", - " and: ''", - "{}: '{}'".format(match_func_name, good_pattern), - " with: 'show_fixtures_per_test.py OK'", - ] - assert lines == expected - # check the function twice to ensure we don't accumulate the internal buffer for i in range(2): with pytest.raises(pytest.fail.Exception) as e: func = getattr(lm, function) func(good_pattern) obtained = str(e.value).splitlines() - check_failure_lines(obtained) + if function == "no_fnmatch_line": + assert obtained == [ + "nomatch: '{}'".format(good_pattern), + " and: 'cachedir: .pytest_cache'", + " and: 'collecting ... collected 1 item'", + " and: ''", + "fnmatch: '{}'".format(good_pattern), + " with: 'show_fixtures_per_test.py OK'", + ] + else: + assert obtained == [ + "nomatch: '{}'".format(good_pattern), + " and: 'cachedir: .pytest_cache'", + " and: 'collecting ... collected 1 item'", + " and: ''", + "re.match: '{}'".format(good_pattern), + " with: 'show_fixtures_per_test.py OK'", + ] func = getattr(lm, function) func(bad_pattern) # bad pattern does not match any line: passes |