-
|
Hi, I need something like this pseudo code: I've tried to do that (playing wih config, session. fscollector, pluginmanager and more) but finally I was not successful and I had to workaround it by using My idea is to have offline tool without modifying test code itself. Is there any way to do it, could anyone help me to implement it ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
|
I gave an answer to a similar question a while ago: you can register a plugin that stores the items and run 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. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, from _pytest import config
from _pytest.main import Session
def collect(opts):
conf = config.get_config(opts, plugins=[])
conf.parse(opts)
conf._do_configure()
sess = Session.from_config(config=conf)
conf.hook.pytest_sessionstart(session=sess)
conf.hook.pytest_collection(session=sess)
conf.hook.pytest_collection_finish(session=sess)
return sess.items |
Beta Was this translation helpful? Give feedback.
I gave an answer to a similar question a while ago: you can register a plugin that stores the items and run
pytest.mainwith the plugin supplied. Example code:It would be interesting to know though whether a better approach exists.