草庐IT

Full_Names_Test

全部标签

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 - 防止 setup.py test/pytest 安装额外的依赖项

在我的CI中,我有一个build步骤,它使用pip并使用私有(private)索引等正确设置。然后我有test步骤,它执行pythonsetup.pytest。在这种特殊情况下,test是pytest的别名。Setuptools和PIP以不同方式解析包依赖性,这导致测试步骤尝试重新安装某些包。我想阻止这种情况。有没有办法通过Setuptools配置(最好)或PyTest配置来做到这一点?更新:通过流行的需求repo来举例说明我遇到的问题https://github.com/vartec/example_repo_setuptools_issue 最佳答案

python - 如何在优雅地保存在 Django 1.5 之前使用 full_clean() 进行数据验证?

我觉得Django的模型验证对于那些没有使用内置ModelForm的模型来说有点不方便,虽然不知道为什么。首先,需要手动调用full_clean()。Notethatfull_clean()willnotbecalledautomaticallywhenyoucallyourmodel’ssave()method,norasaresultofModelFormvalidation.InthecaseofModelFormvalidation,Model.clean_fields(),Model.clean(),andModel.validate_unique()areallcalled