python - 防止函数或文件用 Nose 运行?

标签 python testing nose

Nose 将自动运行它在项目中找到的以 test_* 开头的任何函数。 。因此,例如,如果有一个函数名为:

"""
test_server_setup.py
sets up a pristine database to use for testing.
DO NOT RUN ON PROD
"""

def test_server_init():
    drop_all_tables()

...然后当你运行命令nosetests时nose就会运行它从项目的根开始。是我重命名此函数的唯一选择,还是有其他方法可以更改文件以便 Nose 忽略它?

最佳答案

nottest装饰器正是您所需要的:

nose.tools.nottest(func)

Decorator to mark a function or method as not a test

from nose.tools import nottest

@nottest
def test_server_init():
    drop_all_tables()

要排除 Nose 测试发现拾取的文件或目录,请参阅:

关于python - 防止函数或文件用 Nose 运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22721998/

相关文章:

python - 使用 Nose 和 Sqlalchemy 以及固定装置编写 Python 测试类

Python 如何让 MessageboxW 保持在所有其他窗口之上?

python - 将具有多个元素的列表转换为具有多列的数据框

javascript - Jasmine 测试 : how to spy on special function?

c++ - CppUnit的多线程实现?

ruby-on-rails - 了解 RSpec 和 Rails 测试环境

python - NoseTests 的基本设置

python - 关闭 Nose 测试中的覆盖范围

python - 如何阻止同一个字母在列表中出现两次?

python - PyTest 弃用 : 'junit_family default value will change to ' xunit2'