gpt4 book ai didi

python - 使用 nose.run() 或 nose.main() 在特定模块中运行测试

转载 作者:太空狗 更新时间:2023-10-29 20:42:17 25 4
gpt4 key购买 nike

它在文档中提到 ( http://nose.readthedocs.org/en/latest/api/core.html ) 但似乎没有任何示例,并且尝试它似乎在 cwd 中运行所有测试。

最佳答案

试试这个:

测试模块.py:

import logging
import sys

import nose

logging.basicConfig(level=logging.INFO)

#here are some tests in this module
def test_me():
pass

if __name__ == '__main__':
#This code will run the test in this file.'

module_name = sys.modules[__name__].__file__
logging.debug("running nose for package: %s", module_name)

result = nose.run(argv=[sys.argv[0],
module_name,
'-v'])
logging.info("all tests ok: %s", result)

python test_module.py 会让你:

test_module.test_me ... ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
INFO:root:all tests ok: True

关于python - 使用 nose.run() 或 nose.main() 在特定模块中运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23001642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com