草庐IT

test_cases

全部标签

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:无论 CaSE 是什么,检查值是否在列表中

我想检查一个值是否在列表中,无论字母大小写如何,我需要高效地完成它。这是我的:ifvalinlist:但我希望它忽略大小写 最佳答案 check="asdf"checkLower=check.lower()printany(checkLower==val.lower()forvalin["qwert","AsDf"])#printstrue使用any()功能。这种方法很好,因为您不会重新创建包含小写字母的列表,它会迭代列表,因此一旦找到真值,它就会停止迭代并返回。演示:http://codepad.org/dH5DSGLP

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 - map_async 与 apply_async :what should I use in this case

我正在处理一些ascii数据,进行一些操作,然后将所有内容写回另一个文件(由post_processing_0.main完成的工作,不返回任何内容)。我想将代码与多处理模块并行化,请参见以下代码片段:frommultiprocessingimportPoolimportpost_processing_0defchunks(lst,n):return[lst[i::n]foriinxrange(n)]defmain():pool=Pool(processes=proc_num)P={}foriinrange(0,proc_num):P['process_'+str(i)]=pool.ap

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