嗨,我是 python 新手,正在尝试编写工厂男孩测试,但收到此错误
self.client.login(username=user.first_name, password='abc')
NameError: global name 'user' is not defined
class UserFactory(factory.Factory):
class Meta:
model = User
first_name = factory.Sequence(lambda n: "Agent %03d" % n)
last_name = 'Steve'
email = factory.LazyAttribute(lambda obj: '%s@example.com' % obj.first_name)
class UserTest(TestCase):
user = UserFactory()
def test_user_login_client(self):
self.client.login(username=user.first_name, password='some')