Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest incompatible with pytest-tldr #582

Closed
heynemann opened this issue Jan 24, 2022 · 9 comments · Fixed by #583
Closed

pytest incompatible with pytest-tldr #582

heynemann opened this issue Jan 24, 2022 · 9 comments · Fixed by #583
Labels

Comments

@heynemann
Copy link

Describe the bug

When running pytest with syrupy I get an exception.

To reproduce

My pip freeze reports the following pytest related packages (I can include the entire pip freeze if that's important):

pytest==6.2.5
pytest-asyncio==0.17.2
pytest-cov==3.0.0
pytest-forked==1.4.0
pytest-tldr==0.2.4
pytest-xdist==2.5.0
syrupy==1.7.0

I created a new test file called test_file.py:

def test_foo(snapshot):
    actual = "Some computed value!"
    assert actual == snapshot

When runnint with pytest tests/test_file.py I get the following output:

F
==============================================================================
FAIL: tests/test_file.py::test_foo
------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/heynemann/dev/thumbor/tests/test_file.py", line 3, in test_foo
    assert actual == snapshot
AssertionError: assert [+ received] == [- snapshot]
  Snapshot 'test_foo' does not exist!
  + 'Some computed va...

  ...Full output truncated (1 line hidden), use '-vv' to show

------------------------------------------------------------------------------
Ran 1 tests in 0.01s

------------------- snapshot report summary --------------------
Traceback (most recent call last):
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/_pytest/config/__init__.py", line 185, in console_main
    code = main()
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/_pytest/config/__init__.py", line 162, in main
    ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/_pytest/main.py", line 316, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/_pytest/main.py", line 304, in wrap_session
    config.hook.pytest_sessionfinish(
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pytest_tldr.py", line 334, in pytest_sessionfinish
    self.config.hook.pytest_terminal_summary(
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/heynemann/.pyenv/versions/3.10.1/envs/thumbor/lib/python3.10/site-packages/syrupy/__init__.py", line 169, in pytest_terminal_summary
    for line in terminalreporter.config._syrupy.report.lines:
AttributeError: 'NoneType' object has no attribute 'lines'

Expected behavior

Expected the snapshot to be created.

Environment (please complete the following information):

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal
  • Syrupy Version: 1.7.0
  • Python Version: 3.10.1 (also tried with 3.9.9)
  • Pytest version: 6.2.5
@noahnu
Copy link
Collaborator

noahnu commented Jan 24, 2022

This is intended behaviour. You don't have a snapshot and so it's correctly reporting a test failure.

If you expect snapshots to be generated, run pytest with the --snapshot-update cli flag.

@noahnu
Copy link
Collaborator

noahnu commented Jan 24, 2022

The attribute error at the bottom of your stack trace looks like a bug though. That should be a quick fix, but doesn't block you.

@noahnu noahnu closed this as completed Jan 24, 2022
@noahnu noahnu added the wontfix This will not be worked on label Jan 24, 2022
@heynemann
Copy link
Author

That's the bug. It does block as that means I get exit code 1 in the test run, instead of 0 even if the test passes with a snapshot.

@noahnu noahnu reopened this Jan 24, 2022
@noahnu noahnu added wontfix This will not be worked on and removed wontfix This will not be worked on labels Jan 24, 2022
@noahnu
Copy link
Collaborator

noahnu commented Jan 24, 2022

I'm not sure I'm following. The expected behaviour is an exit code of 1. Your test did fail, you were missing a snapshot.

From the Motivation section in the README:

> Soundness: Snapshot tests should uncover even the most minute issues. Unlike other snapshot libraries, Syrupy will fail a test suite if a snapshot does not exist, not just on snapshot differences.

@noahnu
Copy link
Collaborator

noahnu commented Jan 24, 2022

It looks like the stack trace is only printed when using pytest-tldr though. Investigating

@noahnu
Copy link
Collaborator

noahnu commented Jan 24, 2022

Ah I see what you're saying. You get an exit code of 1 even when the snapshot is passing because of the tldr incompatibility.

@noahnu noahnu added bug Something isn't working tool compatibility and removed wontfix This will not be worked on labels Jan 24, 2022
@noahnu noahnu changed the title Issue with simple test pytest incompatible with pytest-tldr Jan 24, 2022
@noahnu
Copy link
Collaborator

noahnu commented Jan 24, 2022

#583 should fix it. Essentially pytest-tldr was manually invoking a pytest hook which seems like bad practice. This was breaking an assumption around the hook order.

@tophat-opensource-bot
Copy link
Contributor

🎉 This issue has been resolved in version 1.7.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@heynemann
Copy link
Author

Thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants