0
votes

I'm trying to patch a function called get_datetime().

The real date time get_datetime() is located under bobs/utils/dtutils and does:

def get_datetime() -> datetime:
    return datetime.now()

this gets used in another place under bobs/generation

where globally in the generation.py file i do:

from utils.dtutils import get_datetime
NAME = f"""{KMTER}/{get_datetime().strftime('%Y-%m-%d')}/dadsdge.fs"""

in the monkey patch i do:

monkey_patch.setattr(
    "bobs.generation.get_datetime",
    datetime.datetime(2021, 11, 18),
)

this doesn't work. I still get now() returned.

I also tried patching bobs.utils.dtutils.get_datetime to no avail either. It definitely finds it because if i make up the function name it says module does not contain bla, so i don't understand why i'm not seeing it set...

Unrelated, but why define get_datetime in the first place? Seems like an unnecessary level of indirection (even if you go with the simpler definition get_datetime = datetime.now).chepner
Can do. Let me know if you know why the monkey patching fails. This seems to be failing if i just try monkey patching a stringcaasswa
"This gets used in another place under bobs/generation where globally in the generation.py file I do [...]": in this case, aren't you missing a "generation" in your patch, like "bobs.generation.generation.get_datetime"?Laurent
no sorry i should have wrote bobs/generation.pycaasswa