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

fix: use the test node location when determining snapshot class name #197

Merged
merged 2 commits into from
Apr 19, 2020

Conversation

iamogbz
Copy link
Collaborator

@iamogbz iamogbz commented Apr 19, 2020

Description

Use the pytest node location to parse the full class name path

Related Issues

Checklist

  • This PR has sufficient test coverage.
  • I will merge this pull request with a semantic title.

Additional Comments

No additional comments.

@codecov
Copy link

codecov bot commented Apr 19, 2020

Codecov Report

Merging #197 into master will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #197   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines          867       868    +1     
=========================================
+ Hits           867       868    +1     

@iamogbz iamogbz requested a review from noahnu April 19, 2020 04:23
@iamogbz iamogbz changed the title fix: use the final class when determining snapshot name fix: use the test node location when determining snapshot class name Apr 19, 2020
@iamogbz iamogbz marked this pull request as ready for review April 19, 2020 04:24
@@ -16,8 +17,8 @@ def __init__(self, node: Any):

@property
def classname(self) -> Optional[str]:
classes = self._node.obj.__qualname__.split(".")[:-1]
return ".".join(classes) if classes else None
_, __, qualname = self._node.location
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are you seeing documentation for "location"?

Copy link
Collaborator

@noahnu noahnu Apr 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah found it. This is "Item" not "Node": https://docs.pytest.org/en/latest/_modules/_pytest/nodes.html#Item, although I don't see where the 3rd element of the tuple is defined

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

@iamogbz iamogbz Apr 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's Function which inherits from Item and for our use PyobjMixin
https://docs.pytest.org/en/latest/_modules/_pytest/python.html#Function

With the location property from Item using the reportinfo method overwritten in PyobjMixin

https://github.com/pytest-dev/pytest/blob/7d5f5a878598aaa7f3e100ef6a97bcd13c1b408d/src/_pytest/python.py#L315-L330

@iamogbz iamogbz merged commit 1010c94 into master Apr 19, 2020
@iamogbz iamogbz deleted the fix-195 branch April 19, 2020 17:38
syrupy-bot pushed a commit that referenced this pull request Apr 19, 2020
## [0.3.12](v0.3.11...v0.3.12) (2020-04-19)

### Bug Fixes

* use the test node location when determining snapshot class name ([#197](#197)) ([1010c94](1010c94))
@syrupy-bot
Copy link
Contributor

🎉 This PR is included in version 0.3.12 🎉

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 this pull request may close these issues.

Shared test mixins that use the snapshot fixture save under wrong name
3 participants