Add better warning msg for deprecated warns(None)
This commit is contained in:
		
							parent
							
								
									6ae71a2c2b
								
							
						
					
					
						commit
						dbe66d97b4
					
				|  | @ -103,7 +103,8 @@ HOOK_LEGACY_PATH_ARG = UnformattedWarning( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| WARNS_NONE_ARG = PytestDeprecationWarning( | WARNS_NONE_ARG = PytestDeprecationWarning( | ||||||
|     "Please pass an explicit Warning type or tuple of Warning types." |     "Passing None to catch any warning has been deprecated, pass no arguments instead:\n" | ||||||
|  |     " Replace pytest.warns(None) by simply pytest.warns()." | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| # You want to make some `__init__` or function "private". | # You want to make some `__init__` or function "private". | ||||||
|  |  | ||||||
|  | @ -183,6 +183,7 @@ def test_hookproxy_warnings_for_fspath(tmp_path, hooktype, request): | ||||||
| def test_warns_none_is_deprecated(): | def test_warns_none_is_deprecated(): | ||||||
|     with pytest.warns( |     with pytest.warns( | ||||||
|         PytestDeprecationWarning, |         PytestDeprecationWarning, | ||||||
|         match="Please pass an explicit Warning type or tuple of Warning types.", |         match=r"Passing None to catch any warning has been deprecated, pass no arguments instead:\n Replace pytest.warns\(None\) by simply pytest.warns\(\).", | ||||||
|     ): |     ): | ||||||
|         pytest.warns(None) |         with pytest.warns(None): | ||||||
|  |             pass | ||||||
|  |  | ||||||
|  | @ -307,6 +307,7 @@ class TestWarns: | ||||||
|         assert str(record[1].message) == "runtime" |         assert str(record[1].message) == "runtime" | ||||||
| 
 | 
 | ||||||
|     def test_record_only_none_deprecated_warn(self) -> None: |     def test_record_only_none_deprecated_warn(self) -> None: | ||||||
|  |         # This should become an error when WARNS_NONE_ARG is removed in Pytest 7.0 | ||||||
|         with warnings.catch_warnings(): |         with warnings.catch_warnings(): | ||||||
|             warnings.simplefilter("ignore") |             warnings.simplefilter("ignore") | ||||||
|             with pytest.warns(None) as record: |             with pytest.warns(None) as record: | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue