我有一个简单的fixture.yml
文件:
label:
body: "<%= variable %>"
Run Code Online (Sandbox Code Playgroud)
问题是ERB代码被解析为加载fixture的一部分,而我实际上希望body实际上是"<%= variable%>"(非插值).
如何逃避ERB标记?
我的DoctrineFixturesBundle已安装,我可以通过命令行加载夹具但是,如何从功能测试中加载夹具?
我正在学习pytest,我用pylint把代码搞定了.但是pylint仍抱怨:
W0621: Redefining name %r from outer scope (line %s)
对于pytest的以下示例:
# test_wallet.py
@pytest.fixture
def my_wallet():
'''Returns a Wallet instance with a zero balance'''
return Wallet()
@pytest.mark.parametrize("earned,spent,expected", [
(30, 10, 20),
(20, 2, 18),
])
def test_transactions(my_wallet, earned, spent, expected):
my_wallet.add_cash(earned)
my_wallet.spend_cash(spent)
assert my_wallet.balance == expected
Run Code Online (Sandbox Code Playgroud)
my_wallet
从外部范围重新定义名称.
我找到了解决方法,_
为夹具名称添加前缀:_my_wallet
.
如果我想将灯具保存在与功能相同的文件中,那么最佳做法是什么?
_
?pylint
检查以进行测试?有谁知道如何使用sql fixture加载auth.User的初始数据?对于我的模型,我在一个名为sql的文件夹中有一个<modelname> .sql文件,syncdb可以很好地完成它的工作.但我不知道如何为auth.User模型做到这一点.我用谷歌搜索了它,但没有成功.
提前致谢,
阿尔
我有一个"用户"对象的夹具(只是默认的Django auth),我正在尝试创建一个"Profile"对象的夹具.每个配置文件与用户对象具有一对一的关系,并为该用户定义了一些更多的自定义内容.
据我所知,在夹具中处理外键的常规方法是将外来对象的主键硬编码到夹具中.有没有办法避免这样做?
基本上,我试图在夹具中使用"用户":用户名'而不是"用户":pk'.
有没有办法做到这一点?
我可以使用文件名轻松填充Django夹具中的FileField或ImageField字段,但该文件不存在,当我尝试测试我的应用程序时,它失败,因为该文件不存在.
如何正确填充Django夹具中的FileField或Imagefield,以便文件本身也可用?
NUnit-console 2.6.3有时会打印出以下错误消息,而不是运行测试.以下是我的Jenkins测试构建日志的摘录:
00:05:02.982 Process 'nunit-console-x86' [PID 3684] has begun profiling.
00:05:03.698 NUnit-Console version 2.6.3.13283
00:05:03.698 Copyright (C) 2002-2012 Charlie Poole.
00:05:03.698 Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
00:05:03.698 Copyright (C) 2000-2002 Philip Craig.
00:05:03.698 All Rights Reserved.
00:05:03.698
00:05:03.698 Runtime Environment -
00:05:03.701 OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
00:05:03.701 CLR Version: 2.0.50727.5485 ( Net 3.5 )
00:05:03.701
00:05:03.795 ProcessModel: Default DomainUsage: Single
00:05:03.795 Execution Runtime: net-3.5
00:05:33.886 Unable to locate …
Run Code Online (Sandbox Code Playgroud) 我正在使用fixture来测试Pylons应用程序,但我偶然发现了一个问题.
假设我有这样的数据集:
class CompanyData(DataSet):
class test_company:
company_full_name = u'Firma T?st'
company_short_name = u'T?stCo'
class UserData(DataSet):
class test_user:
user_login = 'testuser'
user_password = 'test'
company = CompanyData.test_company
Run Code Online (Sandbox Code Playgroud)
现在,问题是,当我在功能测试中使用这些数据时(如http://farmdev.com/projects/fixture/using-fixture-with-pylons.html所述),我无法获取id (主键)公司.
在我的应用程序中,用户登录后应重定向到公司资料页面,这就是我需要公司ID的原因.测试看起来或多或少像这样:
self.app.post(url(controller='main', action='login'), params={
'login': UserData.test_user.user_login,
'password': UserData.test_user.user_password
})
response = self.app.get(url(
controller='events', action='index',
company_id=UserData.test_user.company.company_id, # This doesn't work
view='active'))
assert ... in response
Run Code Online (Sandbox Code Playgroud)
第一个请求登录用户,第二个请求检查登录后是否可以访问公司配置文件页面.
这样我得到:
AttributeError:类test_company没有属性'company_id'
我也尝试过:
UserData.test_user.company.ref('company_id')
Run Code Online (Sandbox Code Playgroud)
但它导致:
<Ref.RefValue for CompanyData.test_company.company_id(尚未加载)>
这对我来说似乎很奇怪...为什么不装?
有没有办法找出什么是主键?
我正在尝试在类 skipif 装饰器中使用 pytest 固定装置(范围=模块),但是我收到一条错误消息,指出未定义固定装置。这可能吗?
conftest.py 有一个名为“target”的模块范围的夹具,它返回一个 CurrentTarget 对象。CurrentTarget 对象有一个函数 isCommandSupported。test_mytest.py 有一个包含十几个测试函数的类 Test_MyTestClass。我想根据夹具 target.isCommandSupported 跳过 Test_MyTestClass 中的所有测试,所以我用 skipif 装饰 Test_MyTestClass ,例如:
@pytest.mark.skipif(not target.isCommandSupprted('commandA), reason=command not supported')
class Test_MyTestClass:
...
Run Code Online (Sandbox Code Playgroud)
我收到此错误: NameError: name 'target' is not defined
如果我尝试:
@pytest.mark.skipif(not pytest.config.getvalue('tgt').isCommandSupprted('commandA), reason=command not supported')
class Test_MyTestClass:
...
Run Code Online (Sandbox Code Playgroud)
我收到此错误: AttributeError: 'function' object has no attribute 'isCommandSupprted'
我正在学习代码接收,我想知道存根和固定装置之间有什么区别。两者都可以帮助我加载定义明确的数据,并且 kepp 测试很简单。
但是我什么时候用 \Codeception\Util\Stub 什么时候用 \Codeception\Util\Fixtures