测试不同的调用模式

时间:2016-10-27 05:07:46

标签: unit-testing python-3.x functional-testing python-importlib cookiecutter

我想测试cookiecutter生成的项目如何处理多种调用模式。

给出以下生成的项目

proj/
    proj/
        __init__.py
        __main__.py

__init__.py的内容:

def func():
    pass

__main__.py的内容:

from proj import func

def main():
    func()

if __name__ == '__main__':
    main()

(我已经阅读了__main__.__spec__的问题,这不是这个问题的内容。事实上,我想试驾-TDD-我的工作围绕这些问题)

现在我编写测试,其中生成的项目结构和位置已知(例如,可通过pytest fixtures获得)

test_run_proj_script():
    """Test behavior of ``python3 ./proj``"""
    pass # how to run this?

test_run_proj_module():
    """Test behavior of ``python3 -m ./proj``"""
    pass # how to run this?

奖励:为sys.argv注入价值?

0 个答案:

没有答案