草庐IT

Full_Names_Test

全部标签

python 单元测试: can't call decorated test

我有一个相当大的测试套件,我装饰了一些test_*函数。现在我不能通过./test.pyMySqlTestCase.test_foo_double给他们打电话了,python3.2提示:ValueError:nosuchtestmethodin:result.我的装饰器代码如下所示:defprocedure_test(procedure_name,arguments_count,returns):'''Decoratorforproceduretests,thatsimplifiestestingwhetherprocedurewithgivennameisavailable,whet

python - 结构化二维 Numpy 数组 : setting column and row names

我正在尝试找到一种很好的方法来获取二维numpy数组并将列名和行名附加为结构化数组。例如:importnumpyasnpcolumn_names=['a','b','c']row_names=['1','2','3']matrix=np.reshape((1,2,3,4,5,6,7,8,9),(3,3))#TODO:insertmagicherematrix['3']['a']#7我已经能够像这样设置列:matrix.dtype=[(n,matrix.dtype)fornincolumn_names]这让我可以执行matrix[2]['a']但现在我想重命名行以便我可以执行matrix

python :unit test throws <Response streamed [200 OK]> instead of actual output

fromflaskimportjsonify@app.route('/urlinfo/1/',methods=['GET'])defsearch(URL):ifsomething:a=dict(message="everythingisgood"resp=jsonify(a)returnrespelse:a=dict(error="problem")returnjsonify(a)我正在使用curl它curlhttp://127.0.0.1:5000/urlinfo/1/'https://www.youtube.com/'它以json格式返回所需的输出。我为它写了一个单元测试impor

Python 列表理解 : test function return

有没有办法在列表(或字典)理解中测试函数的返回?我想避免这样写:lst=[]forxinrange(10):bar=foo(x)ifbar:lst.append(bar)并改用列表理解。显然,我不想写:[foo(x)forxinrange(10)iffoo(x)]所以呢?[foo(x)forxinrange(10)if???] 最佳答案 怎么样filter(None,map(foo,range(10)))如果您不想保留中间列表,请将map()替换为itertools.imap().和itertools.ifilter(),整个东西可

python - py.test : specifying python_files in the command line

我想在pytest中设置参数python_files。文档说你需要把它放在一个配置文件中,但我想把它作为调用py.test的一部分包含在命令行中,所以我不必添加那个配置文件。这可能吗? 最佳答案 不可能像现在(2.8)那样开箱即用的pytest。pytestparser了解命令行选项(addoption/getoption)和配置文件值(addini/getini),但它们完全不同。可能可以编写一个插件来添加python_files(或任何其他ini值)作为命令行选项。但只添加一个conftest文件肯定是更简单的选择。

python - 运行 py.test 时的 .coveragerc 文件位置

我正在尝试让pytest运行以处理coveragerc文件。我的.coveragerc文件中的设置没有被使用,所以我猜这个文件根本没有被使用。在下面查看我的项目结构和pytest调用!我做错了什么?项目:basepath/lib/basepath/.coveragercbasepath/test/test_libbasepath/test/run.py我从virtualenv调用test/run.pybasepath$pythontest/run.py运行.pyimportpytestpytest.main('test/test_lib-v--cov-reportxml--covlib

python - Django : Listing model field names and values in template

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:Django-Iterateovermodelinstancefieldnamesandvaluesintemplate你好,我试图在模板中列出字段和通用Django模型的相应值。但是我找不到一个相当普遍的问题的内置解决方案。我非常接近解决方案,但找不到出路。view.py代码:defshowdetails(request,template):objects=newivr1_model.objects.all()fields=newivr1_model._meta.get_all_field_names()r

python - 将命令行参数作为参数传递给 py.test fixture

诚然,这不是开始的最佳方式,更重要的是,fixture参数已解析,即Options.get_option()在其他一切之前被调用。建议和建议将不胜感激。来自config.pyclassOptions(object):option=None@classmethoddefget_option(cls):returncls.option来自conftest.py@pytest.yield_fixture(scope='session',autouse=True)defsession_setup():Options.option=pytest.config.getoption('--remot

python - 使用 `django.test.client` 时 400 错误请求

我认为我缺少基本设置。我正在尝试使用Django的测试框架测试我的API。在shell中,我尝试:fromdjango.testimportClientc=Client()r=c.get('/')我得到一个400BadRequest,这不是预期的输出。从命令行使用简单的curl:curlhttp://localhost我得到了预期的输出:{"detail":"Authenticationcredentials...我是否遗漏了一些基本的东西? 最佳答案 您可以在DEBUG为False时使用测试客户端,您只需将“testserver”

Python Nose 测试继承: load unit test fixtures from subclasses

我正在将Python项目的测试套件从unittest转换为nose。该项目现有的框架(基于unittest)相当笨重,包含大量用于测试发现和运行的高度定制的代码,因此我正在尝试迁移到nose以使一切更加精简。但是,我在生成测试套件的代码方面遇到了问题。该项目的框架有两种运行测试的方式。一个是classTestSomething(unittest.TestCase):defsetUp(self):...deftest_x(self):...deftest_y(self):...suite=unittest.TestSuite()suite.addTest(unittest.makeSui