Test that dreload does deep reloads and skips excluded modules.
()
| 16 | |
| 17 | |
| 18 | def test_deepreload(): |
| 19 | "Test that dreload does deep reloads and skips excluded modules." |
| 20 | with TemporaryDirectory() as tmpdir: |
| 21 | with prepended_to_syspath(tmpdir): |
| 22 | tmpdirpath = Path(tmpdir) |
| 23 | with open(tmpdirpath / "A.py", "w", encoding="utf-8") as f: |
| 24 | f.write("class Object:\n pass\nok = True\n") |
| 25 | with open(tmpdirpath / "B.py", "w", encoding="utf-8") as f: |
| 26 | f.write("import A\nassert A.ok, 'we are fine'\n") |
| 27 | import A |
| 28 | import B |
| 29 | |
| 30 | # Test that A is not reloaded. |
| 31 | obj = A.Object() |
| 32 | dreload(B, exclude=["A"]) |
| 33 | assert isinstance(obj, A.Object) is True |
| 34 | |
| 35 | # Test that an import failure will not blow-up us. |
| 36 | A.ok = False |
| 37 | with pytest.raises(AssertionError, match="we are fine"): |
| 38 | dreload(B, exclude=["A"]) |
| 39 | assert len(modules_reloading) == 0 |
| 40 | assert not A.ok |
| 41 | |
| 42 | # Test that A is reloaded. |
| 43 | obj = A.Object() |
| 44 | A.ok = False |
| 45 | dreload(B) |
| 46 | assert A.ok |
| 47 | assert isinstance(obj, A.Object) is False |
| 48 | |
| 49 | |
| 50 | def test_not_module(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…