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

freezegun not working as expected with pytest --import-mode=importlib #431

Open
rciorba opened this issue Nov 22, 2021 · 3 comments
Open

Comments

@rciorba
Copy link

rciorba commented Nov 22, 2021

Hello and thanks for the work on this awesome library!

It seems freezegun.freeze_time doesn't work well when pytest is ran with --import-mode=importlib.

I've noticed importing the datetime class from the datetime module now bypasses freezing (in test code, not in app code):

# this won't be frozen when using importlib mode
from datetime import datetime
datetime.utcnow()


# this still works as expected
import datetime
datetime.datetime.utcnow()

This seems to only impact datetime usage in tests. Application code importing the datetime class from the datetime module still works as expected.

According to the changelog for 6-0-0 the intention is for this mode to become the default in the future, and feedback is being collected on pytest-dev/pytest#7245.

@rciorba
Copy link
Author

rciorba commented Nov 24, 2021

Updated the description to clarify this only affects the usage of the datetime class via "from" import in test code. Usage in application code seems to still work as expected.

@F1ashhimself
Copy link

Faced the same issue.

@bunny-therapist
Copy link

I think I have the same issue. I did not use "--import-mode=importlib", but the source code itself uses importlib. The importing of a module using importlib fails when I add the freeze_time decorator to the test which executes that part of the code.

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

3 participants