I was having issues while using the code of the accepted answer [here](https://stackoverflow.com/questions/20503373/how-to-monkeypatch-pythons-datetime-datetime-now-with-py-test).

*The code works depending on how I do the import of datetime.* Why is that? Is it possible to mock it so it works both ways?

I am using `Python 3.4`. The following code illustrates the problem:

```
import pytest
from datetime import datetime

mockdate = datetime(2000, 1, 1, 0, 0, 0)

@pytest.fixture(autouse=True)
def patch_datetime_now(monkeypatch):
    class mydatetime:
        @classmethod
        def now(cls):
            return mockdate

    monkeypatch.setattr('datetime.datetime', mydatetime)

def test_doesnt_work():
    assert datetime.now() == mockdate

def test_works():
    import datetime
    assert datetime.datetime.now() == mockdate

```