For testing, I want to mock datetime.datetime.now()
like here.
The function I am testing is reading a table via pyarrow:
import pytest
import pyarrow.parquet as pq
import datetime
mockdate = datetime.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 function_to_test():
date = datetime.datetime.now()
some_table = pq.read_table("abc/def")
return some_table, date
def test_function_to_test():
table, date = function_to_test()
assert date == mockdate
For some reason, mocking the now()
function creates this very weird bug in pyarrow:
ValueError: datetime.datetime size changed, may indicate binary incompatibility. Expected 48 from C header, got 32 from PyObject
Any idea how to fix this? Thanks!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…