-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2862 from tom-dalton-fanduel/issue-2836-fixture-c…
…ollection-bug Issue 2836 fixture collection bug
- Loading branch information
Showing
11 changed files
with
109 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
SEP = "/" | ||
|
||
|
||
def _splitnode(nodeid): | ||
"""Split a nodeid into constituent 'parts'. | ||
Node IDs are strings, and can be things like: | ||
'' | ||
'testing/code' | ||
'testing/code/test_excinfo.py' | ||
'testing/code/test_excinfo.py::TestFormattedExcinfo::()' | ||
Return values are lists e.g. | ||
[] | ||
['testing', 'code'] | ||
['testing', 'code', 'test_excinfo.py'] | ||
['testing', 'code', 'test_excinfo.py', 'TestFormattedExcinfo', '()'] | ||
""" | ||
if nodeid == '': | ||
# If there is no root node at all, return an empty list so the caller's logic can remain sane | ||
return [] | ||
parts = nodeid.split(SEP) | ||
# Replace single last element 'test_foo.py::Bar::()' with multiple elements 'test_foo.py', 'Bar', '()' | ||
parts[-1:] = parts[-1].split("::") | ||
return parts | ||
|
||
|
||
def ischildnode(baseid, nodeid): | ||
"""Return True if the nodeid is a child node of the baseid. | ||
E.g. 'foo/bar::Baz::()' is a child of 'foo', 'foo/bar' and 'foo/bar::Baz', but not of 'foo/blorp' | ||
""" | ||
base_parts = _splitnode(baseid) | ||
node_parts = _splitnode(nodeid) | ||
if len(node_parts) < len(base_parts): | ||
return False | ||
return node_parts[:len(base_parts)] == base_parts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Match fixture paths against actual path segments in order to avoid matching folders which share a prefix. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import pytest | ||
|
||
from _pytest import nodes | ||
|
||
|
||
@pytest.mark.parametrize("baseid, nodeid, expected", ( | ||
('', '', True), | ||
('', 'foo', True), | ||
('', 'foo/bar', True), | ||
('', 'foo/bar::TestBaz::()', True), | ||
('foo', 'food', False), | ||
('foo/bar::TestBaz::()', 'foo/bar', False), | ||
('foo/bar::TestBaz::()', 'foo/bar::TestBop::()', False), | ||
('foo/bar', 'foo/bar::TestBop::()', True), | ||
)) | ||
def test_ischildnode(baseid, nodeid, expected): | ||
result = nodes.ischildnode(baseid, nodeid) | ||
assert result is expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters