Git Product home page Git Product logo

Comments (9)

PuercoPop avatar PuercoPop commented on June 25, 2024

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:

  1. standard library imports
  2. related third party imports
  3. local application/library specific imports

from freezegun.

spulec avatar spulec commented on June 25, 2024

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.

jorgearanda avatar jorgearanda commented on June 25, 2024

The warning in the README is gone, but this is still failing for me.

from freezegun.

spulec avatar spulec commented on June 25, 2024

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.

jorgearanda avatar jorgearanda commented on June 25, 2024

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.

spulec avatar spulec commented on June 25, 2024

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.

jorgearanda avatar jorgearanda commented on June 25, 2024

Awesome, thanks!

from freezegun.

spulec avatar spulec commented on June 25, 2024

I have pushed a fix to master that I think will address this. Can you give it a test?

from freezegun.

jorgearanda avatar jorgearanda commented on June 25, 2024

That was extremely fast, and it works. Thanks a lot for fixing this!

from freezegun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.