From 18bc706fdc55f9e6636670550cb34c9b64af27a7 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 2 Apr 2020 15:25:53 +0200 Subject: [PATCH] tests: revisit tests for removed load_module The tests came via c629f6b18 and c61ff31ffa1. The fixes from there are kind of obsoleted by 4cd08f9 (moving to importlib), but it makes sense to keep them as integration tests in general. --- testing/test_assertrewrite.py | 60 +++++++---------------------------- 1 file changed, 11 insertions(+), 49 deletions(-) diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index a045eda2e..7bc853e82 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -1028,74 +1028,36 @@ class TestAssertionRewriteHookDetails: assert _read_pyc(str(source), str(pyc)) is None # no error - def test_reload_is_same(self, testdir): - # A file that will be picked up during collecting. - testdir.tmpdir.join("file.py").ensure() - testdir.tmpdir.join("pytest.ini").write( - textwrap.dedent( - """ + def test_reload_is_same_and_reloads(self, testdir: Testdir) -> None: + """Reloading a (collected) module after change picks up the change.""" + testdir.makeini( + """ [pytest] python_files = *.py - """ - ) - ) - - testdir.makepyfile( - test_fun=""" - import sys - try: - from imp import reload - except ImportError: - pass - - def test_loader(): - import file - assert sys.modules["file"] is reload(file) """ ) - result = testdir.runpytest("-s") - result.stdout.fnmatch_lines(["* 1 passed*"]) - - def test_reload_reloads(self, testdir): - """Reloading a module after change picks up the change.""" - testdir.tmpdir.join("file.py").write( - textwrap.dedent( - """ + testdir.makepyfile( + file=""" def reloaded(): return False def rewrite_self(): with open(__file__, 'w') as self: self.write('def reloaded(): return True') - """ - ) - ) - testdir.tmpdir.join("pytest.ini").write( - textwrap.dedent( - """ - [pytest] - python_files = *.py - """ - ) - ) - - testdir.makepyfile( + """, test_fun=""" import sys - try: - from imp import reload - except ImportError: - pass + from importlib import reload def test_loader(): import file assert not file.reloaded() file.rewrite_self() - reload(file) + assert sys.modules["file"] is reload(file) assert file.reloaded() - """ + """, ) - result = testdir.runpytest("-s") + result = testdir.runpytest() result.stdout.fnmatch_lines(["* 1 passed*"]) def test_get_data_support(self, testdir):