我有以下最小的setup.py:importsetuptoolssetuptools.setup(setup_requires=['pytest-runner'],tests_require=['mock','pytest'],test_suite='tests',python_requires='>=2.7',)运行时pythonsetup.pytest我不断收到以下错误:回溯(最近调用最后):文件“setup.py”,第8行,在python_requires='>=2.7',File"/Users/project/tmp/env/lib/python2.7/site-package
我想要一个所有失败测试的列表,以便在session结束时使用。Pytest允许您定义一个Hookpytest_sessionfinish(session,exitstatus),它在session结束时调用,我希望在其中获得该列表。session是一个_pytest.main.Session实例,具有属性items(类型list),但我找不到该列表中的每个item是否通过或失败。如何在session结束时检索所有失败测试的列表?如何在使用pytest-xdist插件时完成,我想在主进程中获取该列表。使用这个插件,session在master中甚至没有items属性:defpytest_
我有一个重固定测试函数,它在某些固定输入时失败(它应该)。我怎样才能指出这一点?这就是我现在正在做的,也许还有更好的方法。我是py.test的新手,所以我很感激任何提示。下一部分是所有输入灯具。仅供引用,example_datapackage_path在conf.test中定义@pytest.fixture(params=[None,'pooled_col','phenotype_col'])defmetadata_key(self,request):returnrequest.param@pytest.fixture(params=[None,'feature_rename_col'
我关注了一个tutorialFlask-Cache并尝试自己实现它。给定以下示例,为什么Flask不缓存时间?fromflaskimportFlaskimporttimeapp=Flask(__name__)cache=Cache(config={'CACHE_TYPE':'simple'})cache.init_app(app)@app.route('/time')@cache.cached(timeout=50,key_prefix='test')deftest():returntime.ctime()输出始终是当前时间。似乎每次请求都会重新创建缓存。我做错了什么?编辑:我使用Py
我对pytestHook和插件比较陌生,我不知道如何让我的pytest代码给我测试执行摘要和失败原因。考虑代码:classFoo:def__init__(self,val):self.val=valdeftest_compare12():f1=Foo(1)f2=Foo(2)assertf1==f2,"F2doesnotmatchF1"deftest_compare34():f3=Foo(3)f4=Foo(4)assertf3==f4,"F4doesnotmatchF3"当我使用-v选项运行pytest脚本时,它会在控制台上显示以下结果:=========================
我正在尝试使用pytest进行一些单元测试。我正在考虑做这样的事情:actual=b_manager.get_b(complete_set)assertactualisnotNoneassertactual.columns==['bl','direction','day']第一个断言没问题,但第二个断言出现值错误。ValueError:Thetruthvalueofanarraywithmorethanoneelementisambiguous.Usea.any()ora.all()我认为用pytest断言两个不同列表的相等性不是正确的方法。我如何断言数据框列(列表)等于预期列?谢谢
在询问关于sending“304NotModified”forimagesstoredintheintheGoogleAppEnginedatastore的问题之后,我现在有一个关于Cache-Control的问题。我的应用程序现在发送Last-Modified和Etag,但默认情况下GAE还会发送Cache-Control:no-cache。根据thispage:The“no-cache”directive,accordingtotheRFC,tellsthebrowserthatitshouldrevalidatewiththeserverbeforeservingthepagef
如果我有两个参数化的fixture,我如何创建一个测试函数,首先用一个fixture的实例调用,然后用另一个fixture的实例调用?我想创建一个以某种方式连接两个现有装置的新装置是有意义的。这适用于“普通”灯具,但我似乎无法使用参数化灯具。这是我尝试过的一个简化示例:importpytest@pytest.fixture(params=[1,2,3])deflower(request):return"i"*request.param@pytest.fixture(params=[1,2])defupper(request):return"I"*request.param@pytest
我正在测试一个可能会死锁的异步函数。我尝试添加一个fixture来限制函数在引发故障之前只运行5秒,但到目前为止它还没有奏效。设置:pipenv--python==3.6pipenvinstallpytest==4.4.1pipenvinstallpytest-asyncio==0.10.0代码:importasyncioimportpytest@pytest.fixturedefmy_fixture():#attempttostartatimerthatwillstopthetestsomehowasyncio.ensure_future(time_limit())yield'egg
假设我有一个这样的测试套件:classSafeTests(unittest.TestCase):#snip20testfunctionsclassBombTests(unittest.TestCase):#snip10differenttestcases我目前正在做以下事情:suite=unittest.TestSuite()loader=unittest.TestLoader()safetests=loader.loadTestsFromTestCase(SafeTests)suite.addTests(safetests)ifTARGET!='prod':unsafetests=l