|
8 | 8 | from _pytest.pytester import Pytester
|
9 | 9 | from _pytest.pytester import RecordedHookCall
|
10 | 10 | from _pytest.pytester import RunResult
|
| 11 | +from _pytest.reports import CollectReport |
11 | 12 | import pytest
|
12 | 13 |
|
13 | 14 |
|
@@ -71,15 +72,19 @@ def test_collect_imports_disabled(pytester: Pytester) -> None:
|
71 | 72 |
|
72 | 73 | # Verify that the state of hooks
|
73 | 74 | reprec = pytester.inline_run()
|
| 75 | + reports = reprec.getreports("pytest_collectreport") |
| 76 | + modified = reprec.getcalls("pytest_collection_modifyitems") |
74 | 77 | items_collected = reprec.getcalls("pytest_itemcollected")
|
| 78 | + |
| 79 | + assert len(reports) == 5 |
| 80 | + assert len(modified) == 1 |
75 | 81 | assert len(items_collected) == 1
|
76 | 82 | for x in items_collected:
|
77 | 83 | assert x.item._getobj().__name__ == "test_testament"
|
78 | 84 |
|
79 | 85 |
|
80 | 86 | def test_collect_imports_default(pytester: Pytester) -> None:
|
81 | 87 | run_import_class_test(pytester, errors=1)
|
82 |
| - # TODO |
83 | 88 |
|
84 | 89 |
|
85 | 90 | def test_collect_imports_enabled(pytester: Pytester) -> None:
|
@@ -260,7 +265,6 @@ def _test_hook_behaviour_when_collect_off(self, pytester: Pytester) -> None:
|
260 | 265 | }
|
261 | 266 |
|
262 | 267 | def _test_hook_behaviour(self) -> None:
|
263 |
| - print("ABCD", self.collect_outcomes) |
264 | 268 | default = self.collect_outcomes["default"]
|
265 | 269 | collect_off = self.collect_outcomes["collect_off"]
|
266 | 270 |
|
@@ -294,37 +298,20 @@ def _test_hook_behaviour(self) -> None:
|
294 | 298 | off_items = off_items_record.__dict__["item"]
|
295 | 299 | assert def_items.name == off_items.name
|
296 | 300 |
|
297 |
| - # TODO: fix diff: (This will get cleaned up) |
298 |
| - # [ |
299 |
| - # <CollectReport '' lenresult=1 outcome='passed'>, |
300 |
| - # - <CollectReport 'src' lenresult=0 outcome='passed'>, |
301 |
| - # <CollectReport 'tests/foo_test.py::TestDomain' lenresult=1 outcome='passed'>, |
302 |
| - # <CollectReport 'tests/foo_test.py' lenresult=1 outcome='passed'>, |
303 |
| - # <CollectReport 'tests' lenresult=1 outcome='passed'>, |
304 |
| - # - <CollectReport '.' lenresult=2 outcome='passed'>, |
305 |
| - # ? ^ |
306 |
| - # + <CollectReport '.' lenresult=1 outcome='passed'>, |
307 |
| - # ? ^ |
308 |
| - # ] |
309 |
| - |
310 |
| - for x in default["reports"]: |
311 |
| - print("def", x.__dict__) |
312 |
| - |
313 |
| - for x in collect_off["reports"]: |
314 |
| - print("off", x.__dict__) |
315 |
| - |
316 |
| - # The two above loops prints: |
317 |
| - |
318 |
| - # def {'nodeid': '', 'outcome': 'passed', 'longrepr': None, 'result': [<Dir test_hook_behaviour0>], 'sections': []} # noqa: E501 |
319 |
| - # def {'nodeid': 'tests/foo_test.py::TestDomain', 'outcome': 'passed', 'longrepr': None, 'result': [<Function test_important>], 'sections': []} # noqa: E501 |
320 |
| - # def {'nodeid': 'tests/foo_test.py', 'outcome': 'passed', 'longrepr': None, 'result': [<Class TestDomain>], 'sections': []} # noqa: E501 |
321 |
| - # def {'nodeid': 'tests', 'outcome': 'passed', 'longrepr': None, 'result': [<Module foo_test.py>], 'sections': []} # noqa: E501 |
322 |
| - # def {'nodeid': '.', 'outcome': 'passed', 'longrepr': None, 'result': [<Dir tests>], 'sections': []} # noqa: E501 |
323 |
| - # off {'nodeid': '', 'outcome': 'passed', 'longrepr': None, 'result': [<Dir test_hook_behaviour1>], 'sections': []} # noqa: E501 |
324 |
| - # off {'nodeid': 'src', 'outcome': 'passed', 'longrepr': None, 'result': [], 'sections': []} |
325 |
| - # off {'nodeid': 'tests/foo_test.py::TestDomain', 'outcome': 'passed', 'longrepr': None, 'result': [<Function test_important>], 'sections': []} # noqa: E501 |
326 |
| - # off {'nodeid': 'tests/foo_test.py', 'outcome': 'passed', 'longrepr': None, 'result': [<Class TestDomain>], 'sections': []} # noqa: E501 |
327 |
| - # off {'nodeid': 'tests', 'outcome': 'passed', 'longrepr': None, 'result': [<Module foo_test.py>], 'sections': []} # noqa: E501 |
328 |
| - # off {'nodeid': '.', 'outcome': 'passed', 'longrepr': None, 'result': [<Dir src>, <Dir tests>], 'sections': []} # noqa: E501 |
329 |
| - |
330 |
| - assert len(default["reports"]) == len(collect_off["reports"]) |
| 301 | + def compare_report(r1: CollectReport, r2: CollectReport) -> None: |
| 302 | + assert r1.result[0].name == r2.result[0].name |
| 303 | + assert len(r1.result) == len(r2.result) |
| 304 | + assert r1.outcome == r2.outcome |
| 305 | + |
| 306 | + # Function test_important |
| 307 | + compare_report(default["reports"][1], collect_off["reports"][2]) |
| 308 | + # Class TestDomain |
| 309 | + compare_report(default["reports"][2], collect_off["reports"][3]) |
| 310 | + # Module foo_test.py |
| 311 | + compare_report(default["reports"][3], collect_off["reports"][4]) |
| 312 | + |
| 313 | + # + 1 since src dir is collected |
| 314 | + assert len(default["reports"]) + 1 == len(collect_off["reports"]) |
| 315 | + |
| 316 | + # Two Dirs will be collected, src and test. |
| 317 | + assert len(collect_off["reports"][5].result) == 2 |
0 commit comments