Comments (9)
I've just that If I swap the order of the import the testcase works fine, but from the pep8
Imports should be grouped in the following order:
- standard library imports
- related third party imports
- local application/library specific imports
from freezegun.
Yes, this is a known limitation of the library (there's a warning in the README). The other workaround involves just importing the datetime module and using that instead of importing classes from the module. Sorry that there's not currently a better answer.
from freezegun.
The warning in the README is gone, but this is still failing for me.
from freezegun.
Are you running this exact code? It works on my local machine.
If you are using this exact code, can you let me know some more details about your setup? Python version, OS, freezegun version, etc.
If you are not using this exact code, can you show me the code you are using?
from freezegun.
That code works, but this, for instance, fails:
from freezegun import freeze_time
from datetime import datetime as dt
freezer = freeze_time('1980-01-01')
freezer.start()
assert dt.now() == dt(1980,1,1)
...whereas importing datetime.datetime after the call to start()
succeeds:
from freezegun import freeze_time
freezer = freeze_time('1980-01-01')
freezer.start()
from datetime import datetime as dt
assert dt.now() == dt(1980,1,1)
I have similar issues using the @freeze_time
decorator.
I'm on Mac OSX 10.10, python 2.7.1, freezegun 0.2.2.
from freezegun.
Okay. So I think the problem here is the aliasing of the datetime import as dt
.
The following code works:
from freezegun import freeze_time
from datetime import datetime
freezer = freeze_time('1980-01-01')
freezer.start()
assert datetime.now() == datetime(1980,1,1)
This is definitely a bug, but I want to spend some time figuring out the best way to fix it. I've opened a new issue for this at #64.
Thanks for reporting it.
from freezegun.
Awesome, thanks!
from freezegun.
I have pushed a fix to master that I think will address this. Can you give it a test?
from freezegun.
That was extremely fast, and it works. Thanks a lot for fixing this!
from freezegun.
Related Issues (20)
- Issue with dateparser
- Consider adding socketserver to the default ignore list
- Using freezegun during threaded function causes an odd error HOT 6
- 1 min difference when using `auto_tick_seconds`
- Doesnt change the time for subprocess HOT 2
- datetime.utcnow() and datetime.now() return same value HOT 1
- Drop usage of utcfromtimestamp HOT 1
- utcnow is deprecated HOT 1
- Add parameter to increase speed of time when tick=True
- `time_to_freeze.today()` returns wrong time and type if TZ is not 'UTC' in env vars HOT 2
- 'FakeDatetime' object cannot be interpreted as an integer
- Timezone America/Sao_Paulo triggers recursion errors in tests. HOT 3
- Maintenance plans HOT 3
- 1.3.0: `freezegun/__init__.py` is missing new version number HOT 1
- [Discussion] about freezing asyncio HOT 7
- ``PermissionError: [Errno 1] Operation not permitted`` appears when upgrading to ``1.3.0`` HOT 7
- Freezegun doesn't mock pointers to date functions HOT 1
- Tag for 1.2.2 is missing HOT 1
- Python 3.12: Deprecation warnings related to datetime.datetime.utcfromtimestamp HOT 2
- Time is not freezed when using `uvloop` event loop
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freezegun.