platform linux -- Python 3.6.7, pytest-4.4.0, py-1.8.0, pluggy-0.9.0
#example.py
try:
import configparser
except ImportError:
import ConfigParser as configparser
CONFIG = configparser.ConfigParser()
CONFIG.read(sys.argv[1])
ININFO = {i:dict(CONFIG.items(i)) for i in CONFIG.sections()}
DATANAME = ININFO['data']['name']
def somefunction(DATANAME):
"""
This function will take lot of variables from ini file
"""
print(DATANAME)
s1 = "Pass"
s2 = "Fail"
s3 = "Pass"
print(s1, s2, s3)
return [s1, s2, s3]
def test_somefunction():
"""
Test function
- Will check whether all steps are passed or not.
"""
status = somefunction()
for sts in status:
assert sts == 'Pass', "Test has Failed!"
if __name__ == "__main__":
somefunction()
Same like above code I have so many files and all have built-in tests
How I execute is
#sudo python3 example.py inifile.ini
Please let me know How I can execute this with pytest and with out changing the code.
if i replace sys.argv[1]
with filename this work fine as below
sudo python3 -m pytest -s
Guide me how I can handle this.
I added and check below screenshot error image
example ini file test.ini
[data]
name = some.name
age = 22
[data1]
name = someother.name
age = 32