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

Syrupy crashes when used with pytest-flake8 #246

Closed
daphtdazz opened this issue Jun 1, 2020 · 3 comments · Fixed by #247
Closed

Syrupy crashes when used with pytest-flake8 #246

daphtdazz opened this issue Jun 1, 2020 · 3 comments · Fixed by #247
Assignees
Labels

Comments

@daphtdazz
Copy link

daphtdazz commented Jun 1, 2020

Bug description

With the following dependencies in my poetry file:

syrupy = "^0.4.3"
pytest = "^5.4.2"
pytest-flake8 = "^1.0.6"

I have this test file:

test_snapshot.py

def test_a_snapshot(snapshot):
    assert 1 == snapshot

And when I run it I get:

$ py.test --flake8 test_snapshot.py 
============================= test session starts =============================
... blah ...                            

test_snapshot.py::FLAKE8 PASSED                                         [ 50%]
test_snapshot.py::test_a_snapshot PASSED                                [100%]
Traceback (most recent call last):
...
  File "/path/to/venv/lib/python3.7/site-packages/syrupy/report.py", line 104, in <genexpr>
    for node in self.ran_items
  File "/path/to/venv/lib/python3.7/site-packages/syrupy/location.py", line 13, in __init__
    self.modulename = self._node.obj.__module__
AttributeError: 'Flake8Item' object has no attribute 'obj'

To Reproduce

Steps to reproduce the behavior:

  1. Install pytest-flake8 and syrupy
  2. Write a test in a test file that uses snapshot
  3. run py.test --flake8 path/to/your/test.py

Expected behaviour

The test should not fail in tear down and py.test should exit with 0 exit code.

Screenshots

N/A

Environment

  • OS: macOS 10.15.3 Catalina
  • Python Version 3.7.4

Extra info

FWIW I "fixed" this for my install by using the following monkey-patch:

# Monkey patch Flake8Item due to a conflict with syrupy https://github.com/tophat/syrupy/issues/246
import pytest_flake8
pytest_flake8.Flake8Item.obj = type('DummyFlake8Obj', (), {})

But I think it's really a problem with syrupy for assuming the obj attribute will be on the pytest Item.

@noahnu
Copy link
Collaborator

noahnu commented Jun 1, 2020

Thanks for opening this issue. I'll take a look today

@noahnu
Copy link
Collaborator

noahnu commented Jun 1, 2020

Looking into pytest-flake8, it seems like an interesting use of pytest.

In the pytest source, they don't assume node's always have an obj: https://github.com/pytest-dev/pytest/blob/2f406bb9cb8538e5a43551d6eeffe2be80bccefa/src/_pytest/nodes.py#L412.

Either way, I put up a PR with a fix. Just investigating how we could test for this.

noahnu pushed a commit that referenced this issue Jun 2, 2020
* fix: only process valid test nodes in report, close #246

* chore: ignore build metadata

* fix: ensure unused snapshots processed in deterministic order
syrupy-bot pushed a commit that referenced this issue Jun 2, 2020
## [0.4.4](v0.4.3...v0.4.4) (2020-06-02)

### Bug Fixes

* only process valid test nodes in report, close [#246](#246) ([#247](#247)) ([8ed194c](8ed194c))
@syrupy-bot
Copy link
Contributor

🎉 This issue has been resolved in version 0.4.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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