syrusakbary / snapshottest

Snapshot Testing utils for Python 📸

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incompatibility between fastdiff and freezegun

ygormutti opened this issue · comments

All tests which snapshots contain freezegun's FakeDateTime are failing with this error:

_______________________________________________ test_parse _______________________________________________

args = ()
kwargs = {REDACTED 'snapshot': <snapshottest.pytest.PyTestSnapshotTest object at 0x7f735ed47208>}

    def wrapper(*args, **kwargs):
>       with self as time_factory:

../../.local/share/virtualenvs/andamento-n6vHlPty/lib/python3.7/site-packages/freezegun/api.py:585: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../.local/share/virtualenvs/andamento-n6vHlPty/lib/python3.7/site-packages/freezegun/api.py:457: in __enter__
    return self.start()
../../.local/share/virtualenvs/andamento-n6vHlPty/lib/python3.7/site-packages/freezegun/api.py:520: in start
    module_attrs = _get_cached_module_attributes(mod_name, module)
../../.local/share/virtualenvs/andamento-n6vHlPty/lib/python3.7/site-packages/freezegun/api.py:110: in _get_cached_module_attributes
    if _get_module_attributes_hash(module) == module_hash:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

module = <module 'fastdiff._native' from '/home/ygor/.local/share/virtualenvs/andamento-n6vHlPty/lib/python3.7/site-packages/fastdiff/_native.py'>

    def _get_module_attributes_hash(module):
>       return '{0}-{1}'.format(id(module), hashlib.md5(','.join(dir(module)).encode('utf-8')).hexdigest())
E       TypeError: 'str' object is not callable

../../.local/share/virtualenvs/andamento-n6vHlPty/lib/python3.7/site-packages/freezegun/api.py:104: TypeError

PS: this is happening in 0.5.1 release.

I'd rather fix fastdiff or the integration rather than removing it.
We should debug why is happening and fix it rather than reverting the dependency (which is useful for a lot of cases).

Sorry, but it's not clear which use cases fastdiff is useful for that difflib doesn't work. Can you please give some examples?

The commit message introducing fastdiff just says it's for faster diffs. How much faster are we talking about? Speed doesn't seem to be an issue even in a codebase in which we have 22 megabytes of snapshots (and I think we have way too big snapshot tests; when they start getting big devs stop caring about them in code reviews).

I'm asking because, IMHO, it broke things that were working to fix things that weren't broken. So why bother? Why not just revert it? At least while someone interested in fastdiff figures this out outside master branch?

The commit message introducing fastdiff just says it's for faster diffs. How much faster are we talking about? Speed doesn't seem to be an issue even in a codebase in which we have 22 megabytes of snapshots (and I think we have way too big snapshot tests; when they start getting big devs stop caring about them in code reviews).

Fastdiff is about 75 times faster (more info here). This becomes quite important when doing diffs on big snapshots, having a very noticeable speedup.

I'm asking because, IMHO, it broke things that were working to fix things that weren't broken. So why bother? Why not just revert it? At least while someone interested in fastdiff figures this out outside master branch?

Fastdiff pushes a bit the boundaries of what's possible with Python via WebAssembly. I want to make sure the use case is well covered, as it might have other great implications to the rest of the ecosystem. That's why I think is better to fix it, rather than revert it.
Hope it makes sense!

If you could create a repo that helps to reproduce the issue I will happily investigate and try to find a solution asap :)

Sounds like this is something that will likely need to be fixed upstream in fastdiff. Would welcome a snippet or repo with the reproduction, or help resolving this issue.