[Rearranged and snipped so this makes any kind of sense]

On 16/07/2019 16:43, אורי wrote:
On Tue, Jul 16, 2019 at 3:13 PM Rhodri James <rho...@kynesim.co.uk> wrote:
On 16/07/2019 11:08, אורי wrote:
2. I want to override a function called build_suite in an inherited
class.
The function receives an argument "test_labels" which I want to change (I
define it if it's not defined), but I don't do anything with the argument
"extra_tests". Is it possible to include "extra_tests" in *args, **kwargs

Yes.

and how?

Don't list it in your parameters :-)

def build_suite(self, test_labels=None, *args, **kwargs):
      ...
      return super().build_suite(test_labels=test_labels, *args, **kwargs)
>
> Thanks for your explanation. But I tried your code and it doesn't work
> (with Django==1.11.22):
>
> File "<...>\site-packages\django\test\runner.py", line 600, in run_tests
>      suite = self.build_suite(test_labels, extra_tests)
>    File "<...>\speedy\core\base\test\models.py", line 35, in build_suite
>      return super().build_suite(test_labels=test_labels, *args, **kwargs)
> TypeError: build_suite() got multiple values for argument 'test_labels'

Ah, sorry, I was under the impression that you were calling the function with "test_labels" and "extra_tests" as keyword arguments. You can solve the immediate problem by omitting the "=test_labels" bit:

  return super().build_suite(test_labels, *args, **kwargs)

assuming that "test_labels" is the first positional parameter. If it isn't, you've got trouble anyway :-) and you'll need to do some more involved parameter handling.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to