As part of PEP 399 <https://www.python.org/dev/peps/pep-0399/>, an idiom
for testing both C and pure Python versions of a library is suggested
making use if import_fresh_module.

Unfortunately, I'm finding that this is not amazingly robust. We have
this issue: https://bugs.python.org/issue40058, where the tester for
datetime needs to do some funky manipulations
<https://github.com/python/cpython/blob/302e5a8f79514fd84bafbc44b7c97ec636302322/Lib/test/test_datetime.py#L14-L23>to
the state of sys.modules for reasons that are now somewhat unclear, and
still sys.modules is apparently left in a bad state.

When implementing PEP 615, I ran into similar issues and found it very
difficult to get two independent instances of the same module – one with
the C extension blocked and one with it intact. I ended up manually
importing the C and Python extensions and grafting them onto two "fresh"
imports with nothing blocked
<https://github.com/pganssle/zoneinfo/blob/ffd21a6d065e04725e04b37bb430c2559fefd5fa/tests/_support.py#L14>.

This seems to work most of the time in my repo, but when I import it
into CPython, I'm now seeing failures due to this issue. The immediate
symptom is that assertRaises is seeing a mismatch between the exception
raised by the module and the exception *on* the module. Here's the
Travis error
<https://travis-ci.org/github/python/cpython/jobs/683080079#L3154-L3186>
(ignore the part about `tzdata`, that needs to be removed as
misleading), and here's the test
<https://github.com/python/cpython/pull/19909/files#diff-885914f7d01a0c33a25e41809f812068R220-R222>.
Evidently calling module.ZoneInfo("Bad_Zone") is raising a different
module's ZoneInfoNotFoundError in some cases and I have no idea why.

Is anyone familiar more familiar with the import system willing to take
a look at these issues?

Thanks,
Paul

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/6H4E3XDPU4YU4HZEEOBB4RL6ZQMC57YG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to