Skip to content

Commit

Permalink
Test the presence of a _path attribute does not affect repr necessa…
Browse files Browse the repository at this point in the history
…rily

Co-authored-by: Eric Snow <[email protected]>
  • Loading branch information
AlexWaygood and ericsnowcurrently authored Nov 27, 2023
1 parent 4293ced commit 647bafa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Lib/test/test_module/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ def test_module_repr_with_namespace_package_and_custom_loader(self):
self.assertRegex(repr(m), expected_repr_pattern)
self.assertNotIn('from', repr(m))

def test_module_repr_with_fake_namespace_package(self):
m = ModuleType('foo')
loader = BareLoader()
loader._path = ['spam']
spec = importlib.machinery.ModuleSpec("foo", loader)
m.__loader__ = loader
m.__spec__ = spec
expected_repr_pattern = r"<module 'foo' \(<.*\.BareLoader object at .+>\)>"
self.assertRegex(repr(m), expected_repr_pattern)
self.assertNotIn('from', repr(m))
def test_module_finalization_at_shutdown(self):
# Module globals and builtins should still be available during shutdown
rc, out, err = assert_python_ok("-c", "from test.test_module import final_a")
Expand Down

0 comments on commit 647bafa

Please sign in to comment.