I have a file data.py where i get the data that is used in each test depending of the environment, i get the environment with sys.argv since it's specified in CLI.
def env():
if "--env=DEV" in sys.argv:
return 'DEV'
elif "--env=UAT" in sys.argv:
return 'UAT'
elif "--env=PROD" in sys.argv:
return 'PROD'
elif "--env=TE" in sys.argv:
return 'TE'
elif "--env=PERF" in sys.argv:
return 'PERF'
else:
return 'Incorrect environment'
if env() == 'UAT':
policy_list_fnol_ap = ['30-60000550', '30-60000551', '30-60000555', '30-60000727', '30-60000798', '30-60000549']
policy_list_fnol_auto = ['4-65000343', '44-45000075', '44-45000076', '4-65000344']
policy_list_fnol_vida = ['23-54000022', '23-54000023', '17-55000042']
elif env() == 'DEV':
policy_list_fnol_ap = ['30-60000301', '30-60000302', '30-60000303', '30-60000304', '30-60000305', '30-60000300']
policy_list_fnol_auto = ['4-65000178', '44-45000030', '4-65000179', '44-45000031']
policy_list_fnol_vida = ['23-54000020', '23-54000021', '17-55000018']
If i run this with pytest it works great, but when i try to run pararel test with xdist (-n x) i get an error because sys.argv only returns "-c" and i can't get the environmet parameter.
I've read in this article: https://pypi.org/project/pytest-xdist/
Accessing sys.argv from the master node in workers To access the sys.argv passed to the command-line of the master node, use request.config.workerinput["mainargv"].
But my problem is that with that option i need to send it as a fixture and i can't use fixtures in data.py since there is not a class, is just a file with the data.
How can i get the environment parameter from CLI in data.py when i run pararel tests with xdist -n?