小编sre*_*har的帖子

如何在pytest中处理sys.argv?

平台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: …
Run Code Online (Sandbox Code Playgroud)

python pytest python-3.x

5
推荐指数
1
解决办法
7671
查看次数

标签 统计

pytest ×1

python ×1

python-3.x ×1