Skip to content

Possible to collect all pytest tests inside python #8554

Answered by hoefling
jscotka asked this question in Q&A
Discussion options

You must be logged in to vote

I gave an answer to a similar question a while ago: you can register a plugin that stores the items and run pytest.main with the plugin supplied. Example code:

import pytest


class ItemsCollector:
    def pytest_collection_modifyitems(self, items):
        self.items = items[:]


def main():
    collector = ItemsCollector()
    pytest.main(['--collect-only'], plugins=[collector])
    print("collected items:", collector.items)

It would be interesting to know though whether a better approach exists.

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
5 replies
@RonnyPfannschmidt
Comment options

@jscotka
Comment options

@nicoddemus
Comment options

@nicoddemus
Comment options

@jscotka
Comment options

Answer selected by jscotka
Comment options

You must be logged in to vote
2 replies
@RonnyPfannschmidt
Comment options

@jscotka
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants