Skip to content

Commit b7439bf

Browse files
authored
Preserve __package__ attribute from original module
Python 3 modules always have a __package__ attribute when created, initially set to None
1 parent 74ae269 commit b7439bf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

test_apipkg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,14 @@ def test_initpkg_not_transfers_not_existing_attrs(monkeypatch):
263263
mod = ModuleType('hello')
264264
mod.__file__ = "hello.py"
265265
assert not hasattr(mod, '__path__')
266-
assert not hasattr(mod, '__package__')
266+
assert not hasattr(mod, '__package__') or mod.__package__ is None
267267
monkeypatch.setitem(sys.modules, 'hello', mod)
268268
apipkg.initpkg('hello', {})
269269
newmod = sys.modules['hello']
270270
assert newmod != mod
271271
assert newmod.__file__ == py.path.local(mod.__file__)
272272
assert not hasattr(newmod, '__path__')
273-
assert not hasattr(newmod, '__package__')
273+
assert not hasattr(newmod, '__package__') or mod.__package__ is None
274274

275275

276276
def test_initpkg_not_changing_jython_paths(monkeypatch):

0 commit comments

Comments
 (0)