|
1 | 1 | import os
|
| 2 | +import re |
2 | 3 | import warnings
|
3 | 4 |
|
4 | 5 | import pytest
|
@@ -268,20 +269,49 @@ def test_func(fix):
|
268 | 269 | collected = []
|
269 | 270 |
|
270 | 271 | class WarningCollector:
|
271 |
| - def pytest_warning_recorded(self, warning_message, when, nodeid): |
272 |
| - collected.append((str(warning_message.message), when, nodeid)) |
| 272 | + def pytest_warning_recorded(self, warning_message, when, nodeid, location): |
| 273 | + collected.append((str(warning_message.message), when, nodeid, location)) |
273 | 274 |
|
274 | 275 | result = testdir.runpytest(plugins=[WarningCollector()])
|
275 | 276 | result.stdout.fnmatch_lines(["*1 passed*"])
|
276 | 277 |
|
277 | 278 | expected = [
|
278 |
| - ("config warning", "config", ""), |
279 |
| - ("collect warning", "collect", ""), |
280 |
| - ("setup warning", "runtest", "test_warning_captured_hook.py::test_func"), |
281 |
| - ("call warning", "runtest", "test_warning_captured_hook.py::test_func"), |
282 |
| - ("teardown warning", "runtest", "test_warning_captured_hook.py::test_func"), |
| 279 | + ( |
| 280 | + "config warning", |
| 281 | + "config", |
| 282 | + "", |
| 283 | + ( |
| 284 | + r"/tmp/pytest-of-.+/pytest-\d+/test_warning_captured_hook0/conftest.py", |
| 285 | + 3, |
| 286 | + "pytest_configure", |
| 287 | + ), |
| 288 | + ), |
| 289 | + ("collect warning", "collect", "", None), |
| 290 | + ("setup warning", "runtest", "test_warning_captured_hook.py::test_func", None), |
| 291 | + ("call warning", "runtest", "test_warning_captured_hook.py::test_func", None), |
| 292 | + ( |
| 293 | + "teardown warning", |
| 294 | + "runtest", |
| 295 | + "test_warning_captured_hook.py::test_func", |
| 296 | + None, |
| 297 | + ), |
283 | 298 | ]
|
284 |
| - assert collected == expected, str(collected) |
| 299 | + for index in range(len(expected)): |
| 300 | + collected_result = collected[index] |
| 301 | + expected_result = expected[index] |
| 302 | + |
| 303 | + assert collected_result[0] == expected_result[0], str(collected) |
| 304 | + assert collected_result[1] == expected_result[1], str(collected) |
| 305 | + assert collected_result[2] == expected_result[2], str(collected) |
| 306 | + |
| 307 | + if expected_result[3] is not None: |
| 308 | + assert re.match(expected_result[3][0], collected_result[3][0]), str( |
| 309 | + collected |
| 310 | + ) |
| 311 | + assert collected_result[3][1] == expected_result[3][1], str(collected) |
| 312 | + assert collected_result[3][2] == expected_result[3][2], str(collected) |
| 313 | + else: |
| 314 | + assert expected_result[3] == collected_result[3], str(collected) |
285 | 315 |
|
286 | 316 |
|
287 | 317 | @pytest.mark.filterwarnings("always")
|
|
0 commit comments