0

A pytest takes a command line argument whose default value is OS dependant.

This works only on OS X where the value is file.dylib:

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

On Windows this value should be file.dll, on Linux libfile.so.

Is there a way to make the default value work on all OSes?

Danijel
  • 8,198
  • 18
  • 69
  • 133
  • 2
    Does this answer your question? [What OS am I running on?](https://stackoverflow.com/questions/1854/what-os-am-i-running-on) – Peter Nov 04 '19 at 08:50

1 Answers1

1

This does it:

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.')

Call get_lib_name() from parser:

parser.addoption('--filename', type=str, default=get_lib_name() )
Danijel
  • 8,198
  • 18
  • 69
  • 133