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

Off by a microsecond #2

Open
life4u2c opened this issue May 21, 2024 · 2 comments
Open

Off by a microsecond #2

life4u2c opened this issue May 21, 2024 · 2 comments

Comments

@life4u2c
Copy link

Perhaps not the worst thing in the world, but when I updated to 0.1.3, I found I was off by a single microsecond in my test.

I was doing something like
with fake_time('1970-01-01 00:00:07.012')
and in my test, datetime.now() would end up returning a time that represented 1970-01-01 00:00:07.011999

And later, I am testing a certain time has elapsed, but I would have to account for this single microsecond to be off. I am also plugged in with the latest of these dependencies

pytest-cov==5.0.0
pytest-env==1.1.3
pytest-libfaketime==0.1.2
pytest-mock==3.14.0
pytest==8.2.1
pytest-xdist[psutil]==3.6.1

These are not all inclusive of everything in my setup, but hopefully of is enough to help identify any issues. Running in a docker environment with the docker container python:3.8.6 and setting up these environment variables within my Dockerfile

ENV LD_LIBRARY_PATH="/usr/local/lib/python3.8/site-packages/libfaketime/vendor/libfaketime/src"
ENV LD_PRELOAD="libfaketime.so.1"
ENV DONT_FAKE_MONOTONIC="1"
ENV FAKETIME_DID_REEXEC=true
ENV FAKETIME_NO_CACHE="1"

A clue maybe: There may be some pytest-xdist conflict issue. Not everyone on my team was seeing this same problem, and we did not have pytest-xdist pinned to a version, so we may have been on different versions. Trying to put everything to the latest version, available today, and I see this issue with the time being off by 1 microsecond.

@life4u2c
Copy link
Author

Sorry, I may need to provide more clarification.

The problem exists on both 0.1.2 and 0.1.3, but I don't know that it's a problem with this library, and so not sure where to put this issue. It may be some sort of issue with a certain combination of dependencies. I am not sure. I was updating dependencies to resolve another unrelated issue with our setup. And ran into this issue.

@life4u2c
Copy link
Author

I was talking to someone about this, seems other teams in my org have also run into interesting issues. I thought I would provide info on that initial issue, that had me looking at upgrading. With pytest.xdist[psutil] not pinned in our original setup, Some people were experiencing passing tests, and others, who pulled a more recent version were failing tests.

Example:

with fake_time("2018-4-09 19:00:00") as frozen_datetime:
    ...
    frozen_datetime.tick()
    ...

Any of our tests which were incrementing the time with a call to tick() were not experiencing the time move forward. This was our requirements setup that looked like:

pytest-cov==5.0.0
pytest-env==1.1.3
pytest-libfaketime==0.1.2
pytest-mock==3.14.0
pytest==8.1.1
pytest-xdist[psutil]

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

1 participant