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

nodes: keep plugins which subclass Item, File working for a bit more #9279

Merged
merged 2 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,13 @@ def __init__(
nodeid: Optional[str] = None,
**kw,
) -> None:
# The first two arguments are intentionally passed positionally,
# to keep plugins who define a node type which inherits from
# (pytest.Item, pytest.File) working (see issue #8435).
# They can be made kwargs when the deprecation above is done.
super().__init__(
name=name,
parent=parent,
name,
parent,
config=config,
session=session,
nodeid=nodeid,
Expand Down
2 changes: 1 addition & 1 deletion testing/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_subclassing_both_item_and_collector_deprecated(
),
):

class SoWrong(nodes.File, nodes.Item):
class SoWrong(nodes.Item, nodes.File):
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the order which triggers the crash before this patch, and seems to be more common, so I just switched the test to use it.

For reference, in the plugin corpus I couldn't find any which directly do File, Item, but found these which do Item, File:

pytest-translations/pytest_translations/mo_files.py
11:class MoFileItem(Item, File):

pytest-checkipdb/pytest_checkipdb.py
27:class CheckIpdbItem(pytest.Item, pytest.File):

pytest-todo/todo/plugin.py
22:class TodoItem(pytest.Item, pytest.File):

pytest-isort/pytest_isort/__init__.py
167:class IsortItem(pytest.Item, pytest.File):

pytest-reqs/pytest_reqs.py
122:class ReqsItem(pytest.Item, pytest.File):

pytest-mccabe/pytest_mccabe.py
60:class McCabeItem(pytest.Item, pytest.File):

pytest-yapf/pytest_yapf.py
27:class YapfItem(pytest.Item, pytest.File):

pytest-flake8/pytest_flake8.py
95:class Flake8Item(pytest.Item, pytest.File):

pytest-black/pytest_black.py
45:class BlackItem(pytest.Item, pytest.File):

pytest-eradicate/pytest_eradicate.py
48:class EradicateItem(pytest.Item, pytest.File):

pytest-cram/pytest_cram/__init__.py
50:class CramItem(pytest.Item, pytest.File):

def __init__(self, fspath, parent):
"""Legacy ctor with legacy call # don't wana see"""
super().__init__(fspath, parent)
Expand Down