我正在努力在pytest中正确设置我的装置。我总是会遇到missing 1 required positional argument:
错误。这就是我正在尝试的:
@pytest.mark.django_db
class TestCreate:
@pytest.fixture(scope='class')
def user(self):
username = 'testuser'
password = 'mypassword'
user_data = {
'username': username,
'password': password,
}
return user_data
def setup(self, user):
"""Setup for tests to create user and project
"""
user_d = user
print(user_d)
username = user_d['username']
基本上,我只想从我的装置中访问字典。但我得到E TypeError: setup() missing 1 required positional argument: 'user'
我似乎Pytest无法访问我的装置?
非常感谢您的帮助!预先感谢
答案 0 :(得分:0)
您也许可以在一个夹具中完成所有设置。对于错误,您可以将set_up方法标记为固定装置,
@pytest.fixture()
def setup(self, user):
"""Setup for tests to create user and project"""
user_d = user
print(user_d)
username = user_d['username']