我有一个像这样的最热测试:
email_two = generate_email_two()
@pytest.mark.parametrize('email', ['email_one@example.com', email_two])
def test_email_thing(self, email):
... # Run some test with the email parameter现在,作为重构的一部分,我移动了一行:
email_two = generate_email_two()进入它自己的夹具(在一个conftest.py文件中),因为它在其他不同的地方使用。但是,除了直接导入夹具函数之外,还有其他方法在这个测试中引用它吗?我知道funcargs通常是调用一个治具的方式,但在这种情况下,当我想要调用该夹具时,我并不在测试函数中。
发布于 2016-03-21 13:40:18
最后,我在测试函数中设置了一个for循环,遍历了每封电子邮件。就测试输出而言,这不是最好的方法,但它可以完成任务。
import pytest
import fireblog.login as login
pytestmark = pytest.mark.usefixtures("test_with_one_theme")
class Test_groupfinder:
def test_success(self, persona_test_admin_login, pyramid_config):
emails = ['id5489746@mockmyid.com', persona_test_admin_login['email']]
for email in emails:
res = login.groupfinder(email)
assert res == ['g:admin']
def test_failure(self, pyramid_config):
fake_email = 'some_fake_address@example.com'
res = login.groupfinder(fake_email)
assert res == ['g:commenter']https://stackoverflow.com/questions/32721657
复制相似问题