Skip to content

Commit f0b3e80

Browse files
committed
Use new no-match functions to replace previous idiom
1 parent 4163556 commit f0b3e80

21 files changed

+77
-76
lines changed

testing/acceptance_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def test_issue93_initialnode_importing_capturing(self, testdir):
246246
)
247247
result = testdir.runpytest()
248248
assert result.ret == ExitCode.NO_TESTS_COLLECTED
249-
assert "should not be seen" not in result.stdout.str()
249+
result.stdout.no_fnmatch_line("*should not be seen*")
250250
assert "stderr42" not in result.stderr.str()
251251

252252
def test_conftest_printing_shows_if_error(self, testdir):
@@ -954,7 +954,7 @@ def test_with_failing_collection(self, testdir):
954954
result.stdout.fnmatch_lines(["*Interrupted: 1 errors during collection*"])
955955
# Collection errors abort test execution, therefore no duration is
956956
# output
957-
assert "duration" not in result.stdout.str()
957+
result.stdout.no_fnmatch_line("*duration*")
958958

959959
def test_with_not(self, testdir):
960960
testdir.makepyfile(self.source)
@@ -1008,7 +1008,7 @@ def main():
10081008
result = testdir.runpython(target)
10091009
assert result.ret == 0
10101010
result.stderr.fnmatch_lines(["*not found*foo*"])
1011-
assert "INTERNALERROR>" not in result.stdout.str()
1011+
result.stdout.no_fnmatch_line("*INTERNALERROR>*")
10121012

10131013

10141014
def test_import_plugin_unicode_name(testdir):

testing/code/test_excinfo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def test_division_zero():
399399
result = testdir.runpytest()
400400
assert result.ret != 0
401401
result.stdout.fnmatch_lines(["*AssertionError*Pattern*[123]*not found*"])
402-
assert "__tracebackhide__ = True" not in result.stdout.str()
402+
result.stdout.no_fnmatch_line("*__tracebackhide__ = True*")
403403

404404
result = testdir.runpytest("--fulltrace")
405405
assert result.ret != 0
@@ -1343,7 +1343,8 @@ def test(tmpdir):
13431343
)
13441344
result = testdir.runpytest()
13451345
result.stdout.fnmatch_lines(["* 1 failed in *"])
1346-
assert "INTERNALERROR" not in result.stdout.str() + result.stderr.str()
1346+
result.stdout.no_fnmatch_line("*INTERNALERROR*")
1347+
result.stderr.no_fnmatch_line("*INTERNALERROR*")
13471348

13481349

13491350
@pytest.mark.usefixtures("limited_recursion_depth")

testing/logging/test_fixture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test2(caplog):
4646
)
4747
result = testdir.runpytest()
4848
result.stdout.fnmatch_lines(["*log from test1*", "*2 failed in *"])
49-
assert "log from test2" not in result.stdout.str()
49+
result.stdout.no_fnmatch_line("*log from test2*")
5050

5151

5252
def test_with_statement(caplog):

testing/logging/test_reporting.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_foo():
109109
"=* 1 failed in *=",
110110
]
111111
)
112-
assert "DEBUG" not in result.stdout.str()
112+
result.stdout.no_re_match_line("DEBUG")
113113

114114

115115
def test_setup_logging(testdir):
@@ -282,7 +282,7 @@ def test_log_cli(request):
282282
"WARNING*test_log_cli_default_level.py* message will be shown*",
283283
]
284284
)
285-
assert "INFO message won't be shown" not in result.stdout.str()
285+
result.stdout.no_fnmatch_line("*INFO message won't be shown*")
286286
# make sure that that we get a '0' exit code for the testsuite
287287
assert result.ret == 0
288288

@@ -566,7 +566,7 @@ def test_log_cli(request):
566566
"PASSED", # 'PASSED' on its own line because the log message prints a new line
567567
]
568568
)
569-
assert "This log message won't be shown" not in result.stdout.str()
569+
result.stdout.no_fnmatch_line("*This log message won't be shown*")
570570

571571
# make sure that that we get a '0' exit code for the testsuite
572572
assert result.ret == 0
@@ -580,7 +580,7 @@ def test_log_cli(request):
580580
"PASSED", # 'PASSED' on its own line because the log message prints a new line
581581
]
582582
)
583-
assert "This log message won't be shown" not in result.stdout.str()
583+
result.stdout.no_fnmatch_line("*This log message won't be shown*")
584584

585585
# make sure that that we get a '0' exit code for the testsuite
586586
assert result.ret == 0
@@ -616,7 +616,7 @@ def test_log_cli(request):
616616
"PASSED", # 'PASSED' on its own line because the log message prints a new line
617617
]
618618
)
619-
assert "This log message won't be shown" not in result.stdout.str()
619+
result.stdout.no_fnmatch_line("*This log message won't be shown*")
620620

621621
# make sure that that we get a '0' exit code for the testsuite
622622
assert result.ret == 0
@@ -942,15 +942,15 @@ def test_simple():
942942
]
943943
)
944944
elif verbose == "-q":
945-
assert "collected 1 item*" not in result.stdout.str()
945+
result.stdout.no_fnmatch_line("*collected 1 item**")
946946
expected_lines.extend(
947947
[
948948
"*test_collection_collect_only_live_logging.py::test_simple*",
949949
"no tests ran in 0.[0-9][0-9]s",
950950
]
951951
)
952952
elif verbose == "-qq":
953-
assert "collected 1 item*" not in result.stdout.str()
953+
result.stdout.no_fnmatch_line("*collected 1 item**")
954954
expected_lines.extend(["*test_collection_collect_only_live_logging.py: 1*"])
955955

956956
result.stdout.fnmatch_lines(expected_lines)
@@ -983,7 +983,7 @@ def test_simple():
983983

984984
result = testdir.runpytest()
985985

986-
assert "--- live log collection ---" not in result.stdout.str()
986+
result.stdout.no_fnmatch_line("*--- live log collection ---*")
987987

988988
assert result.ret == 0
989989
assert os.path.isfile(log_file)

testing/python/collect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ class Test(object):
11391139
"""
11401140
)
11411141
result = testdir.runpytest()
1142-
assert "TypeError" not in result.stdout.str()
1142+
result.stdout.no_fnmatch_line("*TypeError*")
11431143
assert result.ret == ExitCode.NO_TESTS_COLLECTED
11441144

11451145

testing/python/fixtures.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def test_lookup_error(unknown):
455455
"*1 error*",
456456
]
457457
)
458-
assert "INTERNAL" not in result.stdout.str()
458+
result.stdout.no_fnmatch_line("*INTERNAL*")
459459

460460
def test_fixture_excinfo_leak(self, testdir):
461461
# on python2 sys.excinfo would leak into fixture executions
@@ -2647,7 +2647,7 @@ def test_finish():
26472647
*3 passed*
26482648
"""
26492649
)
2650-
assert "error" not in result.stdout.str()
2650+
result.stdout.no_fnmatch_line("*error*")
26512651

26522652
def test_fixture_finalizer(self, testdir):
26532653
testdir.makeconftest(
@@ -3151,7 +3151,7 @@ def arg1():
31513151
*hello world*
31523152
"""
31533153
)
3154-
assert "arg0" not in result.stdout.str()
3154+
result.stdout.no_fnmatch_line("*arg0*")
31553155

31563156
@pytest.mark.parametrize("testmod", [True, False])
31573157
def test_show_fixtures_conftest(self, testdir, testmod):

testing/python/setup_only.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_arg1(arg1):
2727
result.stdout.fnmatch_lines(
2828
["*SETUP F arg1*", "*test_arg1 (fixtures used: arg1)*", "*TEARDOWN F arg1*"]
2929
)
30-
assert "_arg0" not in result.stdout.str()
30+
result.stdout.no_fnmatch_line("*_arg0*")
3131

3232

3333
def test_show_different_scopes(testdir, mode):

testing/python/show_fixtures_per_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
def test_no_items_should_not_show_output(testdir):
22
result = testdir.runpytest("--fixtures-per-test")
3-
assert "fixtures used by" not in result.stdout.str()
3+
result.stdout.no_fnmatch_line("*fixtures used by*")
44
assert result.ret == 0
55

66

@@ -30,7 +30,7 @@ def test_arg1(arg1):
3030
" arg1 docstring",
3131
]
3232
)
33-
assert "_arg0" not in result.stdout.str()
33+
result.stdout.no_fnmatch_line("*_arg0*")
3434

3535

3636
def test_fixtures_in_conftest(testdir):

testing/test_assertion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ def test_hello():
10331033
result = testdir.runpytest()
10341034
assert "3 == 4" in result.stdout.str()
10351035
result = testdir.runpytest_subprocess("--assert=plain")
1036-
assert "3 == 4" not in result.stdout.str()
1036+
result.stdout.no_fnmatch_line("*3 == 4*")
10371037

10381038

10391039
def test_triple_quoted_string_issue113(testdir):
@@ -1045,7 +1045,7 @@ def test_hello():
10451045
)
10461046
result = testdir.runpytest("--fulltrace")
10471047
result.stdout.fnmatch_lines(["*1 failed*"])
1048-
assert "SyntaxError" not in result.stdout.str()
1048+
result.stdout.no_fnmatch_line("*SyntaxError*")
10491049

10501050

10511051
def test_traceback_failure(testdir):

testing/test_assertrewrite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ def test_rewrite_warning_using_pytest_plugins(self, testdir):
914914
testdir.chdir()
915915
result = testdir.runpytest_subprocess()
916916
result.stdout.fnmatch_lines(["*= 1 passed in *=*"])
917-
assert "pytest-warning summary" not in result.stdout.str()
917+
result.stdout.no_fnmatch_line("*pytest-warning summary*")
918918

919919
def test_rewrite_warning_using_pytest_plugins_env_var(self, testdir, monkeypatch):
920920
monkeypatch.setenv("PYTEST_PLUGINS", "plugin")
@@ -932,7 +932,7 @@ def test():
932932
testdir.chdir()
933933
result = testdir.runpytest_subprocess()
934934
result.stdout.fnmatch_lines(["*= 1 passed in *=*"])
935-
assert "pytest-warning summary" not in result.stdout.str()
935+
result.stdout.no_fnmatch_line("*pytest-warning summary*")
936936

937937

938938
class TestAssertionRewriteHookDetails:
@@ -1124,7 +1124,7 @@ def test_long_repr():
11241124
"""
11251125
)
11261126
result = testdir.runpytest()
1127-
assert "unbalanced braces" not in result.stdout.str()
1127+
result.stdout.no_fnmatch_line("*unbalanced braces*")
11281128

11291129

11301130
class TestIssue925:

testing/test_cacheprovider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def test_always_fails():
327327
result = testdir.runpytest("--lf", "--ff")
328328
# Test order will be failing tests firs
329329
result.stdout.fnmatch_lines(["test_b.py*"])
330-
assert "test_a.py" not in result.stdout.str()
330+
result.stdout.no_fnmatch_line("*test_a.py*")
331331

332332
def test_lastfailed_difference_invocations(self, testdir, monkeypatch):
333333
monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
@@ -660,11 +660,11 @@ def test_lf_and_ff_prints_no_needless_message(self, quiet, opt, testdir):
660660
if quiet:
661661
args.append("-q")
662662
result = testdir.runpytest(*args)
663-
assert "run all" not in result.stdout.str()
663+
result.stdout.no_fnmatch_line("*run all*")
664664

665665
result = testdir.runpytest(*args)
666666
if quiet:
667-
assert "run all" not in result.stdout.str()
667+
result.stdout.no_fnmatch_line("*run all*")
668668
else:
669669
assert "rerun previous" in result.stdout.str()
670670

testing/test_capture.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,12 @@ def test_normal():
609609
*while capture is disabled*
610610
"""
611611
)
612-
assert "captured before" not in result.stdout.str()
613-
assert "captured after" not in result.stdout.str()
612+
result.stdout.no_fnmatch_line("*captured before*")
613+
result.stdout.no_fnmatch_line("*captured after*")
614614
if no_capture:
615615
assert "test_normal executed" in result.stdout.str()
616616
else:
617-
assert "test_normal executed" not in result.stdout.str()
617+
result.stdout.no_fnmatch_line("*test_normal executed*")
618618

619619
@pytest.mark.parametrize("fixture", ["capsys", "capfd"])
620620
def test_fixture_use_by_other_fixtures(self, testdir, fixture):
@@ -650,8 +650,8 @@ def test_captured_print(captured_print):
650650
)
651651
result = testdir.runpytest_subprocess()
652652
result.stdout.fnmatch_lines(["*1 passed*"])
653-
assert "stdout contents begin" not in result.stdout.str()
654-
assert "stderr contents begin" not in result.stdout.str()
653+
result.stdout.no_fnmatch_line("*stdout contents begin*")
654+
result.stdout.no_fnmatch_line("*stderr contents begin*")
655655

656656
@pytest.mark.parametrize("cap", ["capsys", "capfd"])
657657
def test_fixture_use_by_other_fixtures_teardown(self, testdir, cap):
@@ -721,7 +721,7 @@ def pytest_runtest_setup():
721721
testdir.makepyfile("def test_func(): pass")
722722
result = testdir.runpytest()
723723
assert result.ret == 0
724-
assert "hello19" not in result.stdout.str()
724+
result.stdout.no_fnmatch_line("*hello19*")
725725

726726

727727
def test_capture_badoutput_issue412(testdir):
@@ -1388,7 +1388,7 @@ def test_spam_in_thread():
13881388
result = testdir.runpytest_subprocess(str(p))
13891389
assert result.ret == 0
13901390
assert result.stderr.str() == ""
1391-
assert "IOError" not in result.stdout.str()
1391+
result.stdout.no_fnmatch_line("*IOError*")
13921392

13931393

13941394
def test_pickling_and_unpickling_encoded_file():

testing/test_collection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def test_ignored_virtualenvs(self, testdir, fname):
139139

140140
# by default, ignore tests inside a virtualenv
141141
result = testdir.runpytest()
142-
assert "test_invenv" not in result.stdout.str()
142+
result.stdout.no_fnmatch_line("*test_invenv*")
143143
# allow test collection if user insists
144144
result = testdir.runpytest("--collect-in-virtualenv")
145145
assert "test_invenv" in result.stdout.str()
@@ -165,7 +165,7 @@ def test_ignored_virtualenvs_norecursedirs_precedence(self, testdir, fname):
165165
testfile = testdir.tmpdir.ensure(".virtual", "test_invenv.py")
166166
testfile.write("def test_hello(): pass")
167167
result = testdir.runpytest("--collect-in-virtualenv")
168-
assert "test_invenv" not in result.stdout.str()
168+
result.stdout.no_fnmatch_line("*test_invenv*")
169169
# ...unless the virtualenv is explicitly given on the CLI
170170
result = testdir.runpytest("--collect-in-virtualenv", ".virtual")
171171
assert "test_invenv" in result.stdout.str()
@@ -364,7 +364,7 @@ def pytest_configure(config):
364364
testdir.makepyfile(test_world="def test_hello(): pass")
365365
result = testdir.runpytest()
366366
assert result.ret == ExitCode.NO_TESTS_COLLECTED
367-
assert "passed" not in result.stdout.str()
367+
result.stdout.no_fnmatch_line("*passed*")
368368
result = testdir.runpytest("--XX")
369369
assert result.ret == 0
370370
assert "passed" in result.stdout.str()
@@ -857,7 +857,7 @@ def test_exit_on_collection_with_maxfail_smaller_than_n_errors(testdir):
857857
["*ERROR collecting test_02_import_error.py*", "*No module named *asdfa*"]
858858
)
859859

860-
assert "test_03" not in res.stdout.str()
860+
res.stdout.no_fnmatch_line("*test_03*")
861861

862862

863863
def test_exit_on_collection_with_maxfail_bigger_than_n_errors(testdir):
@@ -996,12 +996,12 @@ def test_collect_init_tests(testdir):
996996
result.stdout.fnmatch_lines(
997997
["<Package */tests>", " <Module test_foo.py>", " <Function test_foo>"]
998998
)
999-
assert "test_init" not in result.stdout.str()
999+
result.stdout.no_fnmatch_line("*test_init*")
10001000
result = testdir.runpytest("./tests/__init__.py", "--collect-only")
10011001
result.stdout.fnmatch_lines(
10021002
["<Package */tests>", " <Module __init__.py>", " <Function test_init>"]
10031003
)
1004-
assert "test_foo" not in result.stdout.str()
1004+
result.stdout.no_fnmatch_line("*test_foo*")
10051005

10061006

10071007
def test_collect_invalid_signature_message(testdir):

testing/test_conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def pytest_addoption(parser):
187187
)
188188
result = testdir.runpytest("-h", "--confcutdir=%s" % x, x)
189189
result.stdout.fnmatch_lines(["*--xyz*"])
190-
assert "warning: could not load initial" not in result.stdout.str()
190+
result.stdout.no_fnmatch_line("*warning: could not load initial*")
191191

192192

193193
@pytest.mark.skipif(
@@ -648,5 +648,5 @@ def pytest_addoption(parser):
648648
)
649649
)
650650
result = testdir.runpytest("-h", x)
651-
assert "argument --xyz is required" not in result.stdout.str()
651+
result.stdout.no_fnmatch_line("*argument --xyz is required*")
652652
assert "general:" in result.stdout.str()

testing/test_doctest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ def foo():
239239
]
240240
)
241241
# lines below should be trimmed out
242-
assert "text-line-2" not in result.stdout.str()
243-
assert "text-line-after" not in result.stdout.str()
242+
result.stdout.no_fnmatch_line("*text-line-2*")
243+
result.stdout.no_fnmatch_line("*text-line-after*")
244244

245245
def test_docstring_full_context_around_error(self, testdir):
246246
"""Test that we show the whole context before the actual line of a failing
@@ -1177,7 +1177,7 @@ def auto(request):
11771177
"""
11781178
)
11791179
result = testdir.runpytest("--doctest-modules")
1180-
assert "FAILURES" not in str(result.stdout.str())
1180+
result.stdout.no_fnmatch_line("*FAILURES*")
11811181
result.stdout.fnmatch_lines(["*=== 1 passed in *"])
11821182

11831183
@pytest.mark.parametrize("scope", SCOPES)
@@ -1209,7 +1209,7 @@ def auto(request):
12091209
"""
12101210
)
12111211
result = testdir.runpytest("--doctest-modules")
1212-
assert "FAILURES" not in str(result.stdout.str())
1212+
str(result.stdout.no_fnmatch_line("*FAILURES*"))
12131213
result.stdout.fnmatch_lines(["*=== 1 passed in *"])
12141214

12151215

0 commit comments

Comments
 (0)