Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.6.0: pytest fails with python 3.10 on tests/compat/py38.py #32

Open
kloczek opened this issue Jun 19, 2024 · 2 comments
Open

5.6.0: pytest fails with python 3.10 on tests/compat/py38.py #32

kloczek opened this issue Jun 19, 2024 · 2 comments

Comments

@kloczek
Copy link

kloczek commented Jun 19, 2024

Looks like on higher versions tests/compat/py38.py should be skipped

==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.10.14, pytest-8.2.2, pluggy-1.5.0
rootdir: /home/tkloczko/rpmbuild/BUILD/tempora-5.6.0
configfile: pytest.ini
collected 23 items / 1 error

========================================================================================== ERRORS ===========================================================================================
__________________________________________________________________________ ERROR collecting tests/test_schedule.py __________________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/tempora-5.6.0/tests/test_schedule.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_schedule.py:11: in <module>
    from .compat.py38 import zoneinfo
E   ImportError: cannot import name 'zoneinfo' from 'tests.compat.py38' (/home/tkloczko/rpmbuild/BUILD/tempora-5.6.0/tests/compat/py38.py)
================================================================================== short test summary info ==================================================================================
ERROR tests/test_schedule.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
===================================================================================== 1 error in 0.19s ======================================================================================
@kloczek
Copy link
Author

kloczek commented Jun 19, 2024

Also ..

[tkloczko@pers-jacek tempora-5.6.0]$ grep -r compat.py38
tempora/schedule.py:>>> from tests.compat.py38 import zoneinfo
tests/test_schedule.py:from .compat.py38 import zoneinfo

Looks like in those places could be used something like

if sys.version_info >= (3, 9):
    import zoneinfo
else:
    from .compat.py38 import zoneinfo

@jaraco
Copy link
Owner

jaraco commented Aug 5, 2024

Looks like in those places could be used something like

if sys.version_info >= (3, 9):
    import zoneinfo
else:
    from .compat.py38 import zoneinfo

The conditional code is already present in tests.compat.py38. It's set up that way so that tests.compat.py38.zoneinfo is always a valid name regardless of Python version.

if sys.version_info >= (3, 9):
import zoneinfo
else: # pragma: no cover
from backports import zoneinfo # noqa: F401

Since you're on Python 3.10, I'd expect that first line of the branch to be executed and import zoneinfo to be executed, adding zoneinfo to the module namespace.

Note that these tests do run fine in CI, so the problem isn't with the code, but with some factor that's different in your environment.

Can you confirm that in your environment, python3.10 -c 'import zoneinfo' exits with code 0?

If the issue isn't the presence of the zoneinfo module, can you investigate what other differences might be causing the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants