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

provide a rich collection object in the pytest_modifyitems hook #1373

Closed
RonnyPfannschmidt opened this issue Feb 10, 2016 · 2 comments
Closed
Labels
type: enhancement new feature or API change, should be merged into features branch type: feature-branch new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature type: refactoring internal improvements to the code

Comments

@RonnyPfannschmidt
Copy link
Member

plugins that modify the collection have to consider a number of error-prone details

stable sorting/fixture order for those that reorder,
notifying of deselection for those that remove test items

a rough first idea of an potential api could be something like:

items..select_by(node_lastfailed, reason='passed the last test run')  #to run only last failed tests
items.prepend_sort_key(node_lastfailed) " run last failed tests first

the new api should be active by default, but completely revert to the old list-like behavior in case someone does a list operation

in case the behavior is reverted, a pytest warning should be issued on reverting, and in each usage of the new api

this would also help to make #1372 more nice

@RonnyPfannschmidt RonnyPfannschmidt added type: enhancement new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature type: refactoring internal improvements to the code type: feature-branch new feature or API change, should be merged into features branch labels Feb 10, 2016
@RonnyPfannschmidt
Copy link
Member Author

example code now:

def pytest_collection_modifyitems(config, items):
    tiers = config.getoption('tier')
    if not tiers:
        return
    keep, discard = [], []
    for item in items:
        if tier_matches(item, tiers):
            keep.append(item)
        else:
            discard.append(item)

    items[:] = keep
    config.hook.pytest_deselected(items=discard)

code wanted:

def pytest_collection_modifyitems(config, items):
    tiers = config.getoption('tier')
    if tiers:
        items.select_by(
          partial(tier_matches, tiers=tiers),
          deselect_reason='test tier not in %s' % tiers)

@RonnyPfannschmidt
Copy link
Member Author

turns out YAGNI

we may eventually introduce a hook to deselect/uncollect tests based on conditions and allow those hooks to return the reasons

@RonnyPfannschmidt RonnyPfannschmidt closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement new feature or API change, should be merged into features branch type: feature-branch new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature type: refactoring internal improvements to the code
Projects
None yet
Development

No branches or pull requests

1 participant