Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable add_arguments on the runners to work #335

Closed
batiste opened this issue Jun 8, 2016 · 5 comments
Closed

Enable add_arguments on the runners to work #335

batiste opened this issue Jun 8, 2016 · 5 comments
Labels

Comments

@batiste
Copy link

batiste commented Jun 8, 2016

A example is worth a thousand words. I would like to be able to use what is described in the Django documentation here about add_arguments(cls, parser):

https://docs.djangoproject.com/en/1.9/topics/testing/advanced/#django.test.runner.DiscoverRunner

from django_jenkins.runner import CITestSuiteRunner
import unittest

class DummyRunner(CITestSuiteRunner):

    def __init__(self, func=False, **kwargs):
        self.run_functionnal = func
        super(DummyRunner, self).__init__(**kwargs)

    def run_suite(self, suite, **kwargs):
        new_suite = []

        if not self.run_functionnal:
            for test in suite:
                if getattr(test, 'static_handler', None) is None:
                    new_suite.append(test)
        else:
            new_suite = suite

        return super(CITestSuiteRunner, self).run_suite(
            unittest.TestSuite(new_suite), **kwargs)

   @classmethod
    def add_arguments(self, parser):
        parser.add_argument('--func', default=False, help='Enable functionnal test')

Then I would like to run

python manage.py jenkins --func=yes

@batiste
Copy link
Author

batiste commented Jun 8, 2016

Oki I understand why this is not working: Django extends the Command using what is defined by the TEST_RUNNER config here:

https://github.com/django/django/blob/master/django/core/management/commands/test.py#L56

But not by what is defined by the JENKINS_TASK_RUNNER. So the add_arguments on my class has no effect. How should we we fix this?

@batiste
Copy link
Author

batiste commented Jun 8, 2016

I think my PR is working and is a decent solution. Do you need tests for this?

#336

@batiste
Copy link
Author

batiste commented Jun 8, 2016

Actually this is just wrong> Now I am running into troubles if I do this:

JENKINS_TEST_RUNNER = 'lib.runner.TestRunner'
TEST_RUNNER = 'lib.runner.TestRunner'

The arguments are now added twice and it triggers an error it get the argument

argparse.ArgumentError: argument --run-functionnal: conflicting option string(s): --run-functionnal

@batiste
Copy link
Author

batiste commented Jun 8, 2016

Oki so now my runner looks like that

class TestRunner(CITestSuiteRunner):

    def __init__(self, run_functionnal=False, **kwargs):
        self.run_functionnal = run_functionnal
        super(TestRunner, self).__init__(**kwargs)

    def run_suite(self, suite, **kwargs):
        new_suite = []

        if not self.run_functionnal:
            for test in suite:
                if getattr(test, 'static_handler', None) is None:
                    new_suite.append(test)
        else:
            new_suite = suite

        return super(CITestSuiteRunner, self).run_suite(
            unittest.TestSuite(new_suite), **kwargs)

    @classmethod
    def add_arguments(self, parser):
        try:
            parser.add_argument('--run-functionnal',
                action='store_true', help='Run functionnal tests')
            super(CITestSuiteRunner, self).add_arguments(parser)
        except argparse.ArgumentError:
            pass

With those settings

JENKINS_TEST_RUNNER = 'lib.runner.TestRunner'
TEST_RUNNER = 'lib.runner.TestRunner'

And it seems to work again both with python manage.py test and python manage.py jenkins

But this his convoluted

archix pushed a commit to archix/django-jenkins that referenced this issue Nov 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants