Is there a Pytest equivalent to the unittest unittest.TestLoader.loadTestsFromModule() method? #9138
-
I am working on a program that modifies test suites. With the default #create module
code = test.AST.compile()
module = types.ModuleType(test.name)
module.__dict__.update(scope)
exec(code, module.__dict__)
#create suite
suite = unittest.TestLoader().loadTestsFromModule(module)
#run test
suite.run() From everything that I can find in the Pytest documentation, this seems not possible. Does someone know if this is either possible for Pytest or a possible workaround? I don't want to write hundredths of modified tests to the filesystem, as this would be more expensive than keeping them in memory. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
One way I can think of now is to implement your own Lines 210 to 215 in 7720154 |
Beta Was this translation helpful? Give feedback.
One way I can think of now is to implement your own
pytest_pycollect_makemodule
hook, which would return a customModule
object. Here's the default implementation that can be used as basis:pytest/src/_pytest/python.py
Lines 210 to 215 in 7720154