tests/import/import_pkg9.py: Add test for subpackage attribute.
When foo.bar is imported, bar is added as an attribute to foo. Previously this happened on every import, but should only happen on first import. This verifies the behavior for relative imports and overriding. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
parent
dfa7677e2f
commit
99a0c45aef
16
tests/import/import_pkg9.py
Normal file
16
tests/import/import_pkg9.py
Normal file
@ -0,0 +1,16 @@
|
||||
# tests that import only sets subpackage attribute on first import
|
||||
|
||||
import pkg9
|
||||
|
||||
pkg9.mod1()
|
||||
pkg9.mod2()
|
||||
|
||||
import pkg9.mod1
|
||||
|
||||
pkg9.mod1()
|
||||
pkg9.mod2()
|
||||
|
||||
import pkg9.mod2
|
||||
|
||||
pkg9.mod1()
|
||||
print(pkg9.mod2.__name__, type(pkg9.mod2).__name__)
|
5
tests/import/pkg9/__init__.py
Normal file
5
tests/import/pkg9/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
from .mod1 import mod1
|
||||
|
||||
|
||||
def mod2():
|
||||
print("mod2")
|
2
tests/import/pkg9/mod1.py
Normal file
2
tests/import/pkg9/mod1.py
Normal file
@ -0,0 +1,2 @@
|
||||
def mod1():
|
||||
print("mod1")
|
1
tests/import/pkg9/mod2.py
Normal file
1
tests/import/pkg9/mod2.py
Normal file
@ -0,0 +1 @@
|
||||
from . import mod2
|
Loading…
Reference in New Issue
Block a user