Change pytest collection logic for quirky test suite setup #8515
-
The project I'm working on uses a quirky setup for the test suite. Consider a module import unittest
class TestBar(unittest.TestCase):
def test_baz(self, parameter):
pass
instantiate_tests(TestBar) The actual test case is used as template and instantiated based on some parameter. Imagine it as a crude homebrew version of Selecting Of course I could alter the run config of the IDE, but doing so for every test (case) is tedious and error prone. Thus, I thought I write a small
I've looked through the documentation of
Unfortunately, this will never be invoked in case the collection turns up empty. IMO, the other candidates are The documentation on them is fairly minimal, so I'm not sure which one I could use or how to use it. Could someone help me out here or at least give me a nudge in the right direction? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
hi, pmeier def pytest_collection_modifyitems(items): In there, you can modify the case list or order which is executed by pytest, also if you want to adjust them dynamically, maybe you need a configuration file I think, actually, I am seeking a good solution for this issue in my project, but it's more complex, except adjusting the case list, I need to generate the case group continually until my stability test is timeout. Hope this can help you :) |
Beta Was this translation helpful? Give feedback.
-
Hi @pmeier,
Where are the test cases located? Do you inject them in the module's globals? Just to make sure, by "test cases" you mean test classes?
Not sure I follow, I thought >>> import test_foo
>>> hasattr(test_foo, "TestBarSpam")
True
By "this" I assume you mean "run the test from the IDE", but I fail how you can do that without changing the IDE itself... perhaps I'm misunderstanding what you want to do? |
Beta Was this translation helpful? Give feedback.
Hi @pmeier,
Where are the test cases located? Do you inject them in the module's globals?
Just to make sure, by "test cases" you mean test classes?
Not sure I follow, I thought
instantiate_tests
would create the classes and inject them in the module. To exemplify, I thought this would hold true:By "this" I assume you mean "run the test from the ID…