草庐IT

test_compare

全部标签

python - 从 emacs 运行 py.test

如果正在编辑的文件的名称以test_开头,我希望C-cC-c运行py.test并在另一个缓冲区中显示输出,否则通常运行py-execute-buffer。我该怎么做?我在python模式下使用emacs23.1.1,可以从命令行访问py.test。 最佳答案 这还没有经过特别好的测试;这只是一个粗略的想法。(defunpy-do-it()(interactive)(if(string-match(rxbos"test_")(file-name-nondirectory(buffer-file-name)))(compile"py.t

python - 默认跳过测试,除非 py.test 中存在命令行参数

我有一个持续2天的长期测试,我不想将其包含在常规测试运行中。我也不想键入命令行参数,这会在每次常规测试运行时取消选择它和其他测试。当我确实需要时,我更愿意选择默认取消选择的测试。我尝试将测试从test_longrun重命名为longrun并使用命令py.testmytests.py::longrun但这不起作用。 最佳答案 除了上面的pytest_configure解决方案,我还找到了pytest.mark.skipif。你需要将pytest_addoption()放入conftest.pydefpytest_addoption(p

Python 文档测试 : skip a test conditionally

我知道如何使用#doctest:+SKIP跳过doctest,但我不知道如何根据运行时条件有时跳过测试.例如:>>>ifos.path.isfile("foo"):...open("foo").readlines()...else:...pass#doctest:+SKIP['hello','world']这就是我想做的事情。我也会接受运行测试的解决方案,但如果不满足条件(即无条件运行测试但修改预期结果),则将预期结果更改为带有回溯的异常。 最佳答案 如果您不想对输出进行测试,您可以返回一个特殊值。让我们调用_skip这个特殊值:如

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 - 值错误 : Series lengths must match to compare when matching dates in Pandas

我提前为提出这样一个基本问题道歉,但我很困惑。这是一个非常简单的虚拟示例。我在Pandas中匹配日期时遇到一些问题,我不知道为什么。df=pd.DataFrame([[1,'2016-01-01'],[2,'2016-01-01'],[3,'2016-01-02'],[4,'2016-01-03']],columns=['ID','Date'])df['Date']=df['Date'].astype('datetime64')假设我想匹配上面df中的第1行。我事先知道我要匹配ID1。而且我也知道我想要的日期,事实上,我将直接从df的第1行提取该日期以使其无懈可击。some_id=1s

Python/ flask 错误 : "ImportError: cannot import name _compare_digest"

对于Windows,我关注thisFlasktutorial当我遇到以下错误时:C:\Users\GregoryGundersen\Documents\Research\flask-test>pythonrun.pyTraceback(mostrecentcalllast):File"run.py",line2,infromappimportappFile"C:\Users\GregoryGundersen\Documents\Research\flask-test\app\__init__.py",line1,infromflaskimportFlaskFile"C:\Python2

python - Java 中 Comparables 的 Python 等价物是什么?

我有以下形式的字典:{:{'link':u'/story/4/tvb-adapters-simulator-simulatorAdapter/SimulatorAdapter','name':u'Simulate'},:{'link':'/story/step/3','name':u'ViewResults'},:{'link':'/story/step/2','name':u'Analyze'}}Category是表示数据库实例的类。现在我有以下实例:现在这不是同一个实例。我的意思是,我从数据库中获取所有值并创建字典。然后过了一会儿我得到一个id并从数据库中检索实例。现在它们不是同一