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

Do not rely on _makeitem when collecting instances #21

Closed
Closed
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
32 changes: 12 additions & 20 deletions pytest_relaxed/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,15 @@ def _getobj(self):
setattr(obj, name, value)
return obj

# Stub for pytest >=3.0,<3.3 where _makeitem did not exist
def makeitem(self, *args, **kwargs):
return self._makeitem(*args, **kwargs)

def _makeitem(self, name, obj):
# More pytestmark skipping.
if name == "pytestmark":
return
# NOTE: no need to modify collect() this time, just mutate item
# creation. TODO: but if collect() is still public, let's move to that
# sometime, if that'll work as well.
superb = super(SpecInstance, self)
attr = "_makeitem" if hasattr(superb, "_makeitem") else "makeitem"
item = getattr(superb, attr)(name, obj)
# Replace any Class objects with SpecClass; this will automatically
# recurse.
# TODO: can we unify this with SpecModule's same bits?
if isinstance(item, Class):
item = SpecClass(item.name, item.parent)
return item
def collect(self):
items = super(SpecInstance, self).collect()
collected = []
for item in items:
# Replace any Class objects with SpecClass, and recurse into it.
if isinstance(item, Class):
cls = SpecClass.from_parent(item.parent, name=item.name)
for item in cls.collect():
collected.append(item)
else:
collected.append(item)
return collected