Q: Can I share global variables when calling pytest from Python code 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.

A: 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

