-
Notifications
You must be signed in to change notification settings - Fork 276
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
PyPy3.10 test failures due to datetime mocking: TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types, got MagicMock
#2708
Comments
Well that does seem annoying... I would really like to avoid new dependencies if possible. This looks like it would be manageable as just a test dependency, but still: Trying to come up with some alternatives:
Skipping seems preferable to me when compared to a new dependency. |
Skipping them would mean that there would be an uncovered code path on PyPy, wouldn't it? Then that path would be susceptible to actually hitting another problem on PyPy. And libfaketime sounds like a much heavier dependency than freezegun. Perhaps the mocking could be modified not to cause the problem. After all, the problem stems from using |
Mock `datetime.datetime.now()` directly rather than the complete `datetime` class, in order to fix compatibility with the pure Python `datetime` stdlib implementation used on PyPy. The original code failed as it replaced the class with a `MagicMock` instance, while the new one just overrides the method with a lambda. Fixes theupdateframework#2708
Sigh, what an annoying thing. PyPy works fine if we override |
I'm afraid I don't have a good way of doing this, short of having conditional mocking code that detects whether we're using pure Python or C implementation, and uses a different code path appropriately. |
Thanks for taking another look. I'll play with it this week a bit as well, we can decide then. |
Yeah, I can't think of a better way to solve this than your original suggestion. freezegun also looks like a sensible module. I'd be happy with a patch like you described, sorry it took a while to get here. I imagine adding freezegun to |
Use freezegun for time mocking instead of manually patching the datetime module, as it provides a more streamlined solution that works both on CPython and on PyPy. Unfortunately, due to differences between the C datetime extension used by CPython, and the pure Python version of datetime (used by PyPy, and as a fallback on CPython), there does not seem to be a trivial way to mock time that would work with both versions. Fixes theupdateframework#2708 Signed-off-by: Michał Górny <[email protected]>
Filed #2716 |
Use freezegun for time mocking instead of manually patching the datetime module, as it provides a more streamlined solution that works both on CPython and on PyPy. Unfortunately, due to differences between the C datetime extension used by CPython, and the pure Python version of datetime (used by PyPy, and as a fallback on CPython), there does not seem to be a trivial way to mock time that would work with both versions. Fixes theupdateframework#2708 Signed-off-by: Michał Górny <[email protected]>
Description of issue or feature request:
The test suite currently fails 3 tests on PyPy3.10 7.3.17. This is due to a known limitation of pure Python
datetime
module from CPython. However, CPython normally covers it with a C extension, hiding the problem, but PyPy suffers from it.Current behavior:
Expected behavior:
Tests passing :-).
One possible solution would be to use a more complete time mocking solution, e.g. freezegun. I've been able to quickly confirm that it solves the problem, using a quick patch:
If you agree with this approach, I can make a proper pull request.
The text was updated successfully, but these errors were encountered: