adamchainz / time-machine

Travel through time in your tests.
MIT License
729 stars 34 forks source link

Fix System Error on Python 3.13 and Windows #457

Closed adamchainz closed 5 months ago

adamchainz commented 5 months ago

Fixes #456.

The relevant crash from the test log actually seems to be the initial failure:

AttributeError: module 'time' has no attribute 'clock_gettime_ns'

The above exception was the direct cause of the following exception:

...

>       _time_machine.patch_if_needed()
E       SystemError: <built-in function patch_if_needed> returned a result with an exception set

PyObject_GetAttrString fails to get clock_gettime and clock_gettime_ns on Windows because they only exist on Unix. It returns NULL and each time sets the AttributeError as the current error. patch_if_needed did not clear this, leading to Python's call check to raise a SystemError caused by the AttributeError, making time-machine fail to start travelling.

I'm not sure which exact change in Python made this failure occur, so far it seems the SystemError should have been raised on older versions too. Ah well.

@gaborbernat I haven’t got a Windows setup for verifying this on - would you mind trying this on your test suite?

gaborbernat commented 5 months ago

@gaborbernat I haven’t got a Windows setup for verifying this on - would you mind trying this on your test suite?

I also do not have one :D used the Windows GHA to catch this :D

adamchainz commented 5 months ago

Okay, I tested on Windows in CI too, in #458. The test suite is not ready to run on Windows without more work, so I’m going to merge and release this without any test for now.

adamchainz commented 5 months ago

Please give 2.14.2 a try!