【问题标题】:Django : DiscoverRunner overriding raise errorDjango:DiscoverRunner 覆盖引发错误
【发布时间】:2023-03-13 02:50:01
【问题描述】:

我目前正在尝试定义另一个 test_runner。 为此,我更改了我的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:我使用的是 django 1.9

【问题讨论】:

    标签: python django testing overriding manage.py


    【解决方案1】:

    我并没有真正解决我的问题,但我可以逃避这个问题。 我无法在__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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-23
      • 2021-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多