Django:DiscoverRunner覆盖rais

2024-04-25 12:27:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试定义另一个测试运行程序。 为此,我更改了settings.py

TEST_RUNNER = 'test_runner.MezzoTestsRunner'

这是我的MezzoTestsRunner类:

class MezzoTestsRunner(DiscoverRunner):

    def __init__(self):
        super(MezzoTestsRunner,self).__init__(keepdb=True)  

然后我使用命令:python manage.py test

  File "manage.py", line 29, in <module>
execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/test.py", line 74, in execute
    super(Command, self).execute(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/test.py", line 89, in handle
    test_runner = TestRunner(**options)
TypeError: __init__() got an unexpected keyword argument 'verbosity'

我真的很惊讶有这个结果。。有人已经有同样的经历了吗?你知道吗

谢谢:)

PS:我用的是django1.9


Tags: djangoinpycoreselfexecutelibpackages
1条回答
网友
1楼 · 发布于 2024-04-25 12:27:33

我没有真正解决我的问题,但我可以逃避这个问题。 我无法在__init__()中更改keepdb,因此我在run_tests()方法中更改了它:

class MezzoTestsRunner(DiscoverRunner):

    def run_tests(self, test_labels, extra_tests=None, **kwargs):
        self.keepdb=True
        super(MezzoTestsRunner,self).run_tests(test_labels,extra_tests, **kwargs)

相关问题 更多 >