Fix tests and add aditional cases
As requested by review.
👌 Address code review for tests
			
			
This commit is contained in:
		
							parent
							
								
									1654b77ca0
								
							
						
					
					
						commit
						9fc9b2926f
					
				|  | @ -624,6 +624,10 @@ def test_removed_in_pytest4_warning_as_error(testdir, change_default): | ||||||
|         assert change_default in ("ini", "cmdline") |         assert change_default in ("ini", "cmdline") | ||||||
|         result.stdout.fnmatch_lines(["* 1 passed in *"]) |         result.stdout.fnmatch_lines(["* 1 passed in *"]) | ||||||
| class TestAssertionWarnings: | class TestAssertionWarnings: | ||||||
|  |     @staticmethod | ||||||
|  |     def result_warns(result): | ||||||
|  |         return result.stdout.fnmatch_lines(["*PytestWarning*"]) | ||||||
|  | 
 | ||||||
|     def test_tuple_warning(self, testdir): |     def test_tuple_warning(self, testdir): | ||||||
|         testdir.makepyfile( |         testdir.makepyfile( | ||||||
|             """ |             """ | ||||||
|  | @ -631,10 +635,11 @@ class TestAssertionWarnings: | ||||||
|                 assert (1,2) |                 assert (1,2) | ||||||
|             """ |             """ | ||||||
|         ) |         ) | ||||||
|         with pytest.warns(pytest.PytestWarning): |         result = testdir.runpytest() | ||||||
|             testdir.runpytest_subprocess() |         assert self.result_warns(result) | ||||||
| 
 | 
 | ||||||
|     def create_file(self, testdir, return_none): |     @staticmethod | ||||||
|  |     def create_file(testdir, return_none): | ||||||
|         testdir.makepyfile( |         testdir.makepyfile( | ||||||
|             """ |             """ | ||||||
|             def foo(return_none): |             def foo(return_none): | ||||||
|  | @ -652,9 +657,27 @@ class TestAssertionWarnings: | ||||||
| 
 | 
 | ||||||
|     def test_none_function_warns(self, testdir): |     def test_none_function_warns(self, testdir): | ||||||
|         self.create_file(testdir, True) |         self.create_file(testdir, True) | ||||||
|         with pytest.warns(pytest.PytestWarning): |         result = testdir.runpytest() | ||||||
|             testdir.runpytest_subprocess() |         assert self.result_warns(result) | ||||||
|  | 
 | ||||||
|  |     def test_assert_is_none_no_warn(self, testdir): | ||||||
|  |         """Tests a more simple case of `test_none_function_warns` where `assert None` is explicitly called""" | ||||||
|  |         testdir.makepyfile( | ||||||
|  |             """ | ||||||
|  |             def foo(return_none): | ||||||
|  |                 if return_none: | ||||||
|  |                     return None | ||||||
|  |                 else: | ||||||
|  |                     return False | ||||||
|  | 
 | ||||||
|  |             def test_foo(): | ||||||
|  |                 assert foo(True) is None | ||||||
|  |             """ | ||||||
|  |         ) | ||||||
|  |         result = testdir.runpytest() | ||||||
|  |         assert not self.result_warns(result) | ||||||
| 
 | 
 | ||||||
|     def test_false_function_no_warn(self, testdir): |     def test_false_function_no_warn(self, testdir): | ||||||
|         self.create_file(testdir, False) |         self.create_file(testdir, False) | ||||||
|         testdir.runpytest_subprocess("-W error:PytestWarning") |         result = testdir.runpytest() | ||||||
|  |         assert not self.result_warns(result) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue