Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Global variables from pytest_namespace hook doesnt seem to work when xdist is used. #1402
To use global variables across my test i have used pytest_namespace hook, Updating these variables seem to work fine without xdist.But when i use xdist to run my test in parallel , These global variables are not updated
Here is my conftest.py file
Here is my test file test_dummy.py
So when i run
i see the global variable my_global_variable getting updated correctly
but when i do
i see the global variable my_global_variable is not updated at all
what iam i missing here?
Python version : 2.7.9
Thanks for the quick response.
Hmm I'm afraid there's no easy way to send back information from the slaves unfortunately, others please correct me if I'm wrong (sending information from master to slaves can be done using the
Could you describe the exact problem you are trying to accomplish? Perhaps with the actual problem others can suggest a different way to accomplish the same thing.
Hmmm for this case in specific I would use a file on disk, by creating a temporary directory on the master node and forwarding that to the workers, which can then use that directory to write any data they want (for example in
Here's a quick howto create this shared directory and have a
def pytest_configure(config): if is_master(config): config.shared_directory = tempdir.mktemp() def pytest_unconfigure(config): if is_master(config): shutil.rmtree(config.shared_directory) def pytest_configure_node(self, node): """xdist hook""" node.slaveinput['shared_dir'] = node.config.shared_directory @pytest.fixture def shared_directory(request): if is_master(request.config): reutrn request.config.shared_directory else: return request.config.slaveinput['shared_dir'] def is_master(config): """True if the code running the given pytest.config object is running in a xdist master node or not running xdist at all. """ return not hasattr(config, 'slaveinput')