![](/img/trans.png)
[英]TypeError: endturn() missing 1 required positional argument: 'self'
[英]TypeError: test_admin_login() missing 1 required positional argument: 'self'
我正在为基于 Django 的 rest API 编写测试用例。 问题出在测试用例类的方法中。 我想在setuptestdata方法中使用test_admin_login方法。 而我无法做到这一点。 我收到了我在标题中提到的错误。
class MyTests(TestCase):
allow_database_queries: True
client = APIClient()
@classmethod
def setUpTestData(cls):
# client = APIClient()
# AUTHENTICATION
# response = cls.client.post(reverse('auth'),data={"username":"admin","password":"ppoopp00"},format='json')
value = cls.test_admin_login()
print(value)
cls.auth_token = cls.test_admin_login(cls)
# CREATE PROJECT
response = cls.client.post(
reverse('projects:project_create'),
data={"platform_subscriber_entity":"NucoinTest"},
format='json',
HTTP_AUTHORIZATION="JWT "+cls.auth_token
)
cls.project_key = response.data["platform_subscriber_id"]
def test_admin_login(self):
"""
Ensure we can create a new account object.
"""
url = reverse('auth')
response = self.client.post(url,data={"username":"admin","password":"testpass"},format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data), 2)
return response.data["access"]
如果任何函数需要self
这意味着您需要先创建它的一个实例才能使用它,并且您使用cls
而不是实例,所以您只需要创建一个实例
cls().test_admin_login(cls)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.