Reputation: 9288
I am calling pytest from Python code like below
import pytest
global_var = "something I like to share as a global variable"
pytest.main()
Is there any way my test code has access to global_var
?
If the answer is no, what are the good options to share data between caller program and my tests?
I know I can write data into a file, but I am hoping to find some better "in memory" options.
Upvotes: 0
Views: 1636
Reputation: 50809
You can add the attribute to pytest
pytest.global_var = 'something I like to share as a global variable'
pytest.main()
And in the test
print(pytest.global_var) # something I like to share as a global variable
Upvotes: 3