草庐IT

statistical-test

全部标签

python - 如果 py.test 的另一个测试失败,我该如何跳过测试?

假设我有这些测试函数:deftest_function_one():assert#etc...deftest_function_two():#shouldonlyruniftest_function_onepassesassert#etc.如何确保test_function_two仅在test_function_one通过时运行(我希望这是可能的)?编辑:我需要这个,因为测试二正在使用测试一验证的属性。 最佳答案 您可以使用名为pytest-dependency的pytest插件.代码可以是这样的:importpytest@pyte

python - py.test : Show local variables in Jenkins

到目前为止,我们通过Jenkins调用py.test。如果测试失败,我们会看到像这样的通常的堆栈跟踪Traceback(mostrecentcalllast):File"/home/u/src/foo/bar/tests/test_x.py",line36,intest_schema_migrationserrors,out))AssertionError:Unknownoutput:["Migrationsfor'blue':",...]如果我能像在Django调试页面中那样看到局部变量(参见https://djangobook.com/wp-content/uploads/figu

python - 没有输出,即使有 `py.test -s`

我想将py.test与hunter结合使用:PYTHONHUNTER="module_startswith='foo'"py.test-s-ktest_bar不幸的是,hunter的输出(trace)不可见。版本:foo_cok_d@aptguettler:~$py.test--versionThisispytestversion3.4.2,importedfrom/home/foo_cok_d/local/lib/python2.7/site-packages/pytest.pycsetuptoolsregisteredplugins:pytest-xdist-1.22.2at/ho

python - 在 sklearn.cross_validation 中使用 train_test_split 和 cross_val_score 的区别

我有一个包含20列的矩阵。最后一列是0/1标签。数据链接是here.我正在尝试使用交叉验证在数据集上运行随机森林。我使用两种方法来做到这一点:使用sklearn.cross_validation.cross_val_score使用sklearn.cross_validation.train_test_split当我做我认为几乎完全相同的事情时,我得到了不同的结果。为了举例说明,我使用上述两种方法运行双重交叉验证,如下面的代码所示。importcsvimportnumpyasnpimportpandasaspdfromsklearnimportensemblefromsklearn.me

python - 在 Flask-SQLAlchemy 中隔离 py.test 数据库 session

我正在尝试使用Flask-SQLAlchemy构建一个Flask应用程序;我使用pytest来测试数据库。其中一个问题似乎是在不同测试之间创建隔离的数据库session。我编写了一个最小的完整示例来突出问题,请注意test_user_schema1()和test_user_schema2()是相同的。文件名:test_db.pyfrommodelsimportUserdeftest_user_schema1(session):person_name='FranClan'uu=User(name=person_name)session.add(uu)session.commit()ass

python - py.test : format failed assert AND print custom message

py.testassertdocs说...ifyouspecifyamessagewiththeassertionlikethis:asserta%2==0,"valuewasodd,shouldbeeven"thennoassertionintrospectiontakesplacesatallandthemessagewillbesimplyshowninthetraceback.Python的内置unittest模块也执行此操作,除非您的TestCase设置longMessage=True.拥有漂亮的断言格式对测试开发人员友好,而自定义消息对业务需求/人性化更友好。当您不在测试上

python - 单元 : stop after first failing test?

我在我的测试框架中使用了以下代码:testModules=["test_foo","test_bar"]suite=unittest.TestLoader().loadTestsFromNames(testModules)runner=unittest.TextTestRunner(sys.stdout,verbosity=2)results=runner.run(suite)returnresults.wasSuccessful()有没有办法让报告(runner.run?)在第一次失败后中止以防止过于冗长? 最佳答案 问题提出九年

python - Django LiveServer测试用例 : User created in in setUpClass method not available in test_method?

我正在使用Django1.4的LiveServerTestCase进行Selenium测试,但在使用setUpClass类方法时遇到了问题。据我了解,MembershipTests.setUpClass在单元测试运行之前运行一次。我已经将代码添加到MembershipTests.setUpClass中的数据库,但是当我运行MembershipTests.test_signup测试时,没有用户被添加到测试中数据库。我做错了什么?我希望我在setUpClass中创建的用户在所有单元测试中都可用。如果我将用户创建代码放入MembershipTests.setUp并运行MembershipTe

python - __test__ = False 魔法属性如何用于测试发现

所以我正在尝试实现类似于单元测试框架执行以下操作的方式:classBaseTest(T.TestCase):#Disablesthistestfrombeingrun__test__=Falsedeftest_foo(self):pass#Howeverthistestispickedupbecauseitdoesn'tdirectlyhave__test__setclassInheritingTest(BaseTest):pass我觉得很奇怪:#>>InheritingTest.__test__#False这会向我表明它没有使用metaclass在构造类型时将__test__设置为T

python Nose : Log tests results to a file with Multiprocess Plugin

我正在尝试将我的测试输出记录到一个文件并同时运行它们。为此,我尝试使用多进程插件和xunit插件。我知道它们不能一起工作,xunit不会记录任何内容,因为mutiprocess不会直接发送输出。https://github.com/nose-devs/nose/issues/2我正在寻找的是允许我将输出写到文件中的任何替代方法。原因是我正在运行Selenium测试,每次出现错误时,堆栈跟踪都非常大,以至于stdout基本上被填满了。缓解的方法也可能有所帮助,关于如何配置日志输出的selenium文档非常稀少。我还尝试了一个非常基本的标准输出重定向:#nosetests>file.txt