草庐IT

Python unittest - 在测试中使用模块和类级别设置函数中定义的变量

我正在使用nosetests进行Python单元测试来试验Pythonclassandmodulefixtures,在我的测试中进行最少的设置。问题是我不确定如何在我的测试中使用setupUpModule和setUpClass函数中定义的任何变量(例如:test_1)。这是我用来尝试的:importunittestdefsetUpModule():a="SetupModulevariable"print"SetupModule"deftearDownModule():print"ClosingModule"classTrialTest(unittest.TestCase):@class

python - 列出 Nosetest 找到的所有测试

我使用nosetests来运行我的单元测试,它运行良好。我想获取nostests找到的所有测试的列表,而无需实际运行它们。有没有办法做到这一点? 最佳答案 版本0.11.1目前可用。您可以在不运行测试的情况下获取测试列表,如下所示:nosetests-v--collect-only 关于python-列出Nosetest找到的所有测试,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions

python - 列出 Nosetest 找到的所有测试

我使用nosetests来运行我的单元测试,它运行良好。我想获取nostests找到的所有测试的列表,而无需实际运行它们。有没有办法做到这一点? 最佳答案 版本0.11.1目前可用。您可以在不运行测试的情况下获取测试列表,如下所示:nosetests-v--collect-only 关于python-列出Nosetest找到的所有测试,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions

python - 当我的项目(Django)发生任何变化时如何自动运行测试?

目前,在我对django项目进行重大更改后,我每隔一段时间就会运行一次pythonmanage.pytest。每当我在项目中更改和保存文件时,是否可以自动运行这些测试?更早地检测错误会很有用(我知道rails在rspec中有类似的东西)。我正在使用Nose和django-nose。提前致谢。 最佳答案 使用entr:$brewinstall进入$找到.-name'*.py'|进入python./manage.py测试或者,为了额外的功劳,将其与ack结合使用:$ack--python|entrpython./manage.pytes

python - 当我的项目(Django)发生任何变化时如何自动运行测试?

目前,在我对django项目进行重大更改后,我每隔一段时间就会运行一次pythonmanage.pytest。每当我在项目中更改和保存文件时,是否可以自动运行这些测试?更早地检测错误会很有用(我知道rails在rspec中有类似的东西)。我正在使用Nose和django-nose。提前致谢。 最佳答案 使用entr:$brewinstall进入$找到.-name'*.py'|进入python./manage.py测试或者,为了额外的功劳,将其与ack结合使用:$ack--python|entrpython./manage.pytes

python - Matplotlib: Nose , Tornado

因为我试图在我的mac上安装jupyter,所以我升级了我的pip。它告诉我一切都很好,但后来我注意到了这一pip:Requirementalreadyup-to-date:pipin/Library/Python/2.7/site-packages/pip-10.0.0b2-py2.7.egg(10.0.0b2)matplotlib1.3.1requiresnose,whichisnotinstalled.matplotlib1.3.1requirestornado,whichisnotinstalled.matplotlib1.3.1hasrequirementnumpy>=1.5

python - Matplotlib: Nose , Tornado

因为我试图在我的mac上安装jupyter,所以我升级了我的pip。它告诉我一切都很好,但后来我注意到了这一pip:Requirementalreadyup-to-date:pipin/Library/Python/2.7/site-packages/pip-10.0.0b2-py2.7.egg(10.0.0b2)matplotlib1.3.1requiresnose,whichisnotinstalled.matplotlib1.3.1requirestornado,whichisnotinstalled.matplotlib1.3.1hasrequirementnumpy>=1.5

python - 如何更改 Python AssertionError 中的消息?

我正在编写以下内容,在比较两个多行Unicode文本block时,我尝试生成一个体面的错误消息。进行比较的内部方法引发了一个断言,但默认解释对我来说毫无用处我需要在代码中添加一些内容,如下所示:defassert_long_strings_equal(one,other):lines_one=one.splitlines()lines_other=other.splitlines()forline1,line2inzip(lines_one,lines_other):try:my_assert_equal(line1,line2)exceptAssertionError,error:#

python - 如何更改 Python AssertionError 中的消息?

我正在编写以下内容,在比较两个多行Unicode文本block时,我尝试生成一个体面的错误消息。进行比较的内部方法引发了一个断言,但默认解释对我来说毫无用处我需要在代码中添加一些内容,如下所示:defassert_long_strings_equal(one,other):lines_one=one.splitlines()lines_other=other.splitlines()forline1,line2inzip(lines_one,lines_other):try:my_assert_equal(line1,line2)exceptAssertionError,error:#

python - 禁用 Python Nose 测试

当使用Python的Nose测试时,可以通过将测试函数的__test__属性设置为false来禁用单元测试。我已经使用以下装饰器实现了这一点:defunit_test_disabled():defwrapper(func):func.__test__=Falsereturnfuncreturnwrapper@unit_test_disableddeftest_my_sample_test()#codehere...但是,这具有将包装器调用为单元测试的副作用。Wrapper将始终通过,但它包含在nosetests输出中。是否有另一种构造装饰器的方法,以便测试不会运行并且不会出现在Nose