I am building a non-intrusive alternative to pytest for running tests as part of a codebase that is in production. I would like to call each test with its own custom 'print' function instance so that I can collect the test use of print for each test individually without modifying the global print function or alter the streams for the rest of the production system.
My goal would be to pass a local to the function without needing the end user to modify the signature of the function to receive a fixture named 'print' as an argument to the test function.
Example:
def test_func(fixture_a):
print("hello!") # this is not the default print function, and no global was created in the file either
I wasn't able to find a way in the inspect module to call a function with a dict to override its locals. Is this something that is possible in python 3.x?
Aucun commentaire:
Enregistrer un commentaire