CleanCut / green

Green is a clean, colorful, fast python test runner.
MIT License
793 stars 75 forks source link

Django parameter #172

Closed charlsagente closed 6 years ago

charlsagente commented 6 years ago

Hi, I'm trying to integrate green into my django tests. Usually after the second test i use the --keepdb argument from command line to save time. I was wondering how can i pass this argument using green, I tried adding this into a config file but I receive a parsing error

configparser.ParsingError: Source contains parsing errors: '<???>'
    [line  2]: '--keepdb\n'

What is the correct way?

CleanCut commented 6 years ago

Can you describe how you are launching your tests, exactly? What config files / commands are you using?

charlsagente commented 6 years ago

I'm trying with

python3 manage.py test --testrunner=green.djangorunner.DjangoRunner

I have sett GREEN_CONFIG={mypath}/green.conf

in green.conf

--keepdb

I also tried with: keepdb=1

CleanCut commented 6 years ago

Oh, I see. The --keepdb option belongs to django, not green, so pass it to django:

python3 manage.py test --keepdb --testrunner=green.djangorunner.DjangoRunner
charlsagente commented 6 years ago

I've tryied but i get this

python3 manage.py test --keepdb --testrunner=green.djangorunner.DjangoRunner
usage: manage.py test [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS]
                      [--pythonpath PYTHONPATH] [--traceback] [--no-color]
                      [--noinput] [--failfast] [--testrunner TESTRUNNER]
                      [--liveserver LIVESERVER] [--green-verbosity VERBOSITY]
                      [test_label [test_label ...]]
manage.py test: error: unrecognized arguments: --keepdb
CleanCut commented 6 years ago

Hmmm, yep. I see the same thing.

CleanCut commented 6 years ago

Found it. I won't be able to issue a new release until tonight, but if you would like to hot-patch your local installation of green, here's the diff:

diff --git a/green/djangorunner.py b/green/djangorunner.py
index bdb057b..548e52d 100644
--- a/green/djangorunner.py
+++ b/green/djangorunner.py
@@ -75,7 +75,7 @@ try:

         def __init__(self, verbosity=-1, **kwargs):

-            super(DjangoRunner, self).__init__()
+            super(DjangoRunner, self).__init__(**kwargs)
             self.verbosity = verbosity
             self.loader = GreenTestLoader()

@@ -87,6 +87,7 @@ try:
                     help="""
                     Green verbosity level for tests.  Value should be an integer
                     that green supports.  For example: --green-verbosity 3""")
+            super(DjangoRunner, cls).add_arguments(parser)

         def run_tests(self, test_labels, extra_tests=None, **kwargs):
             """
CleanCut commented 6 years ago

Fixed in 2.11.1 (just released).

charlsagente commented 6 years ago

Sweet men!! Need to test it again, your library is amazing. If you need some help in testing or any update/feature please tell me and I´ll be glad to help.

CleanCut commented 6 years ago

Thanks, I appreciate it!

Also, thank you for reporting a valid bug! If you would like a free code to my Python Testing with Green course on Udemy, then just let me know what email address you would like me to send the code to. (You can send an email to nathan.stocks@gmail.com if you want the code but don't want to post your email address publicly on github).