A Way To Add Test Specific Params To Each Test Using Pytest
I'm working on automated testing in pytest, and i'm looking for a way to read params from a config file that are specific to a test and add it to the appropriate test. for example
Solution 1:
conftest.py
@pytest.fixture()
def before(request):
print("request.cls name is :-- ",request.cls.__name__)
if request.cls.__name__ == 'Test_exmpl1':
return["username","password"]
elif request.cls.__name__ == 'Test_exmpl2':
return["username2","password2"]
test_module.py
import pytest
class Test_exmpl1():
def test_on_board(self,before):
print("IN CLASS 1")
print("username :-- %s and password is %s"%(before[0],before[1]))
class Test_exmpl2():
def test_on_board(self,before):
print("IN CLASS 2")
print("username :-- %s and password is %s"%(before[0],before[1]))
You can create a file conftest.py like as above and you can use those values in your test file of pytest.
Post a Comment for "A Way To Add Test Specific Params To Each Test Using Pytest"