草庐IT

pytest-cache

全部标签

Python项目目录结构/pytest麻烦

这应该是地球上最简单的问题,但即使经过大量搜索和修补,我仍然很难找到一种“正确”的方式来放置目录结构并设法正确运行pytest等。假设我有一个名为apple的程序。|-README.md|-apple||--__init__.py||--apple.py|-tests||--test_everything.pyapple.py包含一些函数,例如,让我们调用一个eat()。test_everything.py文件包含一些测试,例如asserteat()=="foobar"。太好了,太容易了,但有趣的事情就开始了:苹果目录中的__init__.py怎么样...对吗?是空的还是里面应该有什么

python - pytest 参数化测试是否适用于基于 unittest 类的测试?

我一直在尝试将参数化的@pytest.mark.parametrize测试添加到基于类的单元测试中。classSomethingTests(unittest.TestCase):@pytest.mark.parametrize(('one','two'),[(1,2),(2,3)])deftest_default_values(self,one,two):assertone==(two+1)但是参数化的东西并没有发挥作用:TypeError:test_default_values()takesexactly3arguments(1given)我已经切换到简单的基于类的测试(没有单元测试

python 2.7 functools_lru_cache 虽然安装但不导入

当我尝试导入matplotlib时出现错误Traceback(mostrecentcalllast):File"",line1,inFile"/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py",line128,infrommatplotlib.rcsetupimportdefaultParams,validate_backend,cyclerFile"/usr/local/lib/python2.7/dist-packages/matplotlib/rcsetup.py",line29,infrommatplot

python - django.core.exceptions.ImproperlyConfigured : Requested setting CACHES, 但未配置设置。您必须定义环境变量

我已经尝试了所有能找到的方法来解决这个问题,但现在我的头发开始掉了一点。我收到此错误:django.core.exceptions.ImproperlyConfigured:RequestedsettingCACHES,butsettingsarenotconfigured.YoumusteitherdefinetheenvironmentvariableDJANGO_SETTINGS_MODULEorcallsettings.configure()beforeaccessingsettings.当我这样做时,我的脚本运行良好:python3./manage.pyrunserver但是

python - 使用 Flask,如何修改所有输出的 Cache-Control header ?

我试过用这个@app.after_requestdefadd_header(response):response.headers['Cache-Control']='max-age=300'returnresponse但这会导致出现重复的Cache-Controlheader。我只想要max-age=300,而不是max-age=1209600行!$curl-Ihttp://my.url.here/HTTP/1.1200OKDate:Wed,16Apr201414:24:22GMTServer:ApacheCache-Control:max-age=300Content-Length:

python - 如何使 pytest 固定装置与装饰功能一起使用?

当我装饰具有固定装置作为参数的测试函数时,py.test似乎失败了。defdeco(func):@functools.wraps(func)defwrapper(*args,**kwargs):returnfunc(*args,**kwargs)returnwrapper@pytest.fixturedefx():return0@decodeftest_something(x):assertx==0在这个简单的示例中,我收到以下错误:TypeError:test_something()takesexactly1argument(0given).有没有办法解决这个问题,最好不要过多地修r

python - 如何显示使用 pytest 时跳过某些测试的原因?

我正在使用unittest中的skipIf()在某些条件下跳过测试。@unittest.skipIf(condition),"thisiswhyIskippedthem!")如何告诉py.test显示跳过条件?我知道,对于unittest,我需要启用详细模式(-v),但添加到py.test的相同参数会增加详细程度,但仍不显示跳过原因。 最佳答案 当你运行py.test时,你可以通过-rsx来报告跳过的测试。来自py.test--help:-rcharsshowextratestsummaryinfoasspecifiedbychar

python - "ImportError: file_cache is unavailable"为 Google 服务帐户 file_cache 使用 Python 客户端时

我正在为GSuite使用具有完整域授权的服务帐号。我有一个对Google日历具有只读访问权限的脚本。该脚本工作得很好,但是当我“构建”服务时会引发错误(在后台线程上?)。代码如下:fromoauth2client.service_accountimportServiceAccountCredentialsfromhttplib2importHttpimporturllibimportrequestsfromapiclient.discoveryimportbuildcal_id="my_calendar_id@group.calendar.google.com"scopes=['htt

python - "py.test"与 "pytest"命令

py.test命令在我的情况下失败,而pytest运行完全正常。我使用pytest-flask插件:platformlinux--Python3.5.2,pytest-3.0.2,py-1.4.31,pluggy-0.3.1rootdir:/home/sebastian/develop/py/flask-rest-template,inifile:plugins:flask-0.10.0当我调用$py.test时出现以下错误:Traceback(mostrecentcalllast):File"/usr/local/lib/python3.5/dist-packages/_pytest

python - 如何在pytest下测试单个文件

如何在pytest中测试单个文件?我只能在文档中找到忽略选项,而没有“仅测试此文件”选项。最好这将在命令行而不是setup.cfg上工作,因为我想在ide中运行不同的文件测试。整个套件花费的时间太长。 最佳答案 只需使用文件路径运行pytest类似pytest测试/test_file.py使用::语法在测试文件中运行特定的测试:pytesttest_mod.py::test_func这里的test_func可以是一个测试方法或者一个类(例如:pytesttest_mod.py::TestClass)。更多方式和详情见"Specify