Elffuss BraidHub

kikocis/auto-code-rover public

main · 3.1 KiBRawPermalink
1Module imported twice under import-mode=importlib
2In pmxbot/pmxbot@7f189ad, I'm attempting to switch pmxbot off of pkg_resources style namespace packaging to PEP 420 namespace packages. To do so, I've needed to switch to `importlib` for the `import-mode` and re-organize the tests to avoid import errors on the tests.
3
4Yet even after working around these issues, the tests are failing when the effect of `core.initialize()` doesn't seem to have had any effect.
5
6Investigating deeper, I see that initializer is executed and performs its actions (setting a class variable `pmxbot.logging.Logger.store`), but when that happens, there are two different versions of `pmxbot.logging` present, one in `sys.modules` and another found in `tests.unit.test_commands.logging`:
7
8```
9=========================================================================== test session starts ===========================================================================
10platform darwin -- Python 3.11.1, pytest-7.2.0, pluggy-1.0.0
11cachedir: .tox/python/.pytest_cache
12rootdir: /Users/jaraco/code/pmxbot/pmxbot, configfile: pytest.ini
13plugins: black-0.3.12, mypy-0.10.3, jaraco.test-5.3.0, checkdocs-2.9.0, flake8-1.1.1, enabler-2.0.0, jaraco.mongodb-11.2.1, pmxbot-1122.14.3.dev13+g7f189ad
14collected 421 items / 180 deselected / 241 selected
15run-last-failure: rerun previous 240 failures (skipped 14 files)
16
17tests/unit/test_commands.py E
18>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
19
20cls = <class 'tests.unit.test_commands.TestCommands'>
21
22 @classmethod
23 def setup_class(cls):
24 path = os.path.dirname(os.path.abspath(__file__))
25 configfile = os.path.join(path, 'testconf.yaml')
26 config = pmxbot.dictlib.ConfigDict.from_yaml(configfile)
27 cls.bot = core.initialize(config)
28> logging.Logger.store.message("logged", "testrunner", "some text")
29E AttributeError: type object 'Logger' has no attribute 'store'
30
31tests/unit/test_commands.py:37: AttributeError
32>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
33
34>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB post_mortem (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
35> /Users/jaraco/code/pmxbot/pmxbot/tests/unit/test_commands.py(37)setup_class()
36-> logging.Logger.store.message("logged", "testrunner", "some text")
37(Pdb) logging.Logger
38<class 'pmxbot.logging.Logger'>
39(Pdb) logging
40<module 'pmxbot.logging' from '/Users/jaraco/code/pmxbot/pmxbot/pmxbot/logging.py'>
41(Pdb) import sys
42(Pdb) sys.modules['pmxbot.logging']
43<module 'pmxbot.logging' from '/Users/jaraco/code/pmxbot/pmxbot/pmxbot/logging.py'>
44(Pdb) sys.modules['pmxbot.logging'] is logging
45False
46```
47
48I haven't yet made a minimal reproducer, but I wanted to first capture this condition.
49