@@ -624,17 +624,22 @@ def test():
624624 assert change_default in ("ini" , "cmdline" )
625625 result .stdout .fnmatch_lines (["* 1 passed in *" ])
626626class TestAssertionWarnings :
627+ @staticmethod
628+ def result_warns (result ):
629+ return result .stdout .fnmatch_lines (["*PytestWarning*" ])
630+
627631 def test_tuple_warning (self , testdir ):
628632 testdir .makepyfile (
629633 """
630634 def test_foo():
631635 assert (1,2)
632636 """
633637 )
634- with pytest . warns ( pytest . PytestWarning ):
635- testdir . runpytest_subprocess ( )
638+ result = testdir . runpytest ()
639+ assert self . result_warns ( result )
636640
637- def create_file (self , testdir , return_none ):
641+ @staticmethod
642+ def create_file (testdir , return_none ):
638643 testdir .makepyfile (
639644 """
640645 def foo(return_none):
@@ -652,9 +657,27 @@ def test_foo():
652657
653658 def test_none_function_warns (self , testdir ):
654659 self .create_file (testdir , True )
655- with pytest .warns (pytest .PytestWarning ):
656- testdir .runpytest_subprocess ()
660+ result = testdir .runpytest ()
661+ assert self .result_warns (result )
662+
663+ def test_assert_is_none_no_warn (self , testdir ):
664+ """Tests a more simple case of `test_none_function_warns` where `assert None` is explicitly called"""
665+ testdir .makepyfile (
666+ """
667+ def foo(return_none):
668+ if return_none:
669+ return None
670+ else:
671+ return False
672+
673+ def test_foo():
674+ assert foo(True) is None
675+ """
676+ )
677+ result = testdir .runpytest ()
678+ assert not self .result_warns (result )
657679
658680 def test_false_function_no_warn (self , testdir ):
659681 self .create_file (testdir , False )
660- testdir .runpytest_subprocess ("-W error:PytestWarning" )
682+ result = testdir .runpytest ()
683+ assert not self .result_warns (result )
0 commit comments