I am using Pytest and Pytest-variables with parametrized test functions to try and reduce duplication of code across test cases. I have this working with hard-coded strings within the test module: similar to this; however, I have no idea how to import the variables from my variable file outside of the scope of a function. Any help is greatly appreciated and I understand this may not be possible using pytest-variables, but I wanted to post here to make sure I am not missing something.
Working code
import pytest
account_email_field = [
['test@google.com', 'Site Title', True],
['', '', False ],
['test@google.com', '', False ],
['', 'Default Title', False]
]
@pytest.fixture(params=account_email_field)
def email_field(request):
return [request.param[0], request.param[1], request.param[2]]
def test_sample_spage(email_field):
return [email_field[0], email_field[1], email_field[2]]
None working code, but an example of what I would like.
import pytest
account_email_field = [
[variables['sample_email'], variables['site_title'], True],
[variables['empty'], variables['empty'], False ],
[variables['sample_email'], variables['empty'], False ],
[variables['empty'], variables['site_title'], False]
]
@pytest.fixture(params=account_email_field)
def email_field(request):
return [request.param[0], request.param[1], request.param[2]]
def test_sample_spage(email_field):
return [email_field[0], email_field[1], email_field[2]]