pytest命令行参数:默认值取决于OS?

pytest带有一个命令行参数,其默认值取决于OS。

这仅适用于值为file.dylib的OS X:

def pytest_addoption(parser):
    parser.addoption('--filename',type=str,default='file.dylib')

在Windows上,该值应为file.dll,在Linux libfile.so上。

有没有办法使默认值在所有OS上都能使用?

youchaozan 回答:pytest命令行参数:默认值取决于OS?

做到这一点:

def get_lib_name():
    libnames = {'Windows': 'file.dll','Darwin': 'file.dylib','Linux': 'file.so'}

    osname = platform.system()

    if osname in libnames:
        return libnames[osname]
    else:
        raise OSError('OS not supported.')

从解析器中调用get_lib_name()

parser.addoption('--filename',type=str,default=get_lib_name() )
本文链接:https://www.f2er.com/3168127.html

大家都在问