I am working on a program that modifies test suites.
In the original implementation, there was only support for the unittest framework. I am trying to add support for Pytest now.
With the default unitest module, I could keep the modified tests as ASTs in memory, which I convert to a module, and finally, I can create a test suite from that, and run it.
#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.
Pytest needs the testfiles to function.
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.