python - how to test the same function from various modules using pytest -


i run test function different modules (in 1 module define function calls c++ code , in other module have same function calls different code). way using py.test?

you can use metafunc , create conftest.py file pytest_addoption , pytest_generate_tests functions:

def pytest_addoption(parser):     parser.addoption("--libname", action="append", default=[],                      help="name of tested library")  def pytest_generate_tests(metafunc):     if 'libname' in metafunc.fixturenames:         metafunc.parametrize("libname", metafunc.config.option.libname) 

and in function in tests.py file can use importlib , ask libname:

def test_import(libname):     import importlib     tested_library = importlib.import_module(libname)     ....... 

now, running test should provide name of module want test: py.test tests.py --libname=your_name1 (you can add --libname=your_name2)


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -