/ / Djangoとselenium TypeError:setUpClass()に必須の位置引数が1つありません: 'cls' - django、python-3.x、selenium

DjangoとSelenium TypeError:setUpClass()missing 1必要な位置引数: 'cls' - django、python-3.x、selenium

私は "django v2をセレンで実験しようとしていますが、このエラーが出ました:

======================================================================
ERROR: setUpClass (level.tests.LevelListViewTest)
----------------------------------------------------------------------
TypeError: setUpClass() missing 1 required positional argument: "cls"

----------------------------------------------------------------------
Ran 0 tests in 0.000s

FAILED (errors=1)

これが私のテストの様子です。

from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver


class LevelListViewTest(StaticLiveServerTestCase):

@staticmethod
def setUpClass(cls):
super().setUpClass()
cls.selenium = WebDriver()
cls.selenium.implicitly_wait(10)

@staticmethod
def tearDownClass(cls):
cls.selenium.quit()
cls.selenium.tearDownClass()

def test_level_is_in_admin_panel(self):
self.selenium.get("%s%s" % (self.live_server_url, "/admin/login/?next=/admin/"))

私はデータベースとしてsqliteを使用し、私はすでにスーパーユーザーを作成し、pipを使用してセレンをインストールしました

回答:

回答№1の場合は3

私はあなたがあなたのセットアップと分解関数に@classmethodデコレータが欲しいと思います、@staticmethodはインスタンス用です。


回答№2の場合は0

これらを使用する必要があります @classmethod デコレータではなく @staticmethod.