CleanCut / green

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

Attribute error in Django 2.0 #177

Closed dizballanze closed 6 years ago

dizballanze commented 6 years ago

Hi, seems that green doesn't work with Django 2.0.

# python manage.py test

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/venv/lib/python3.6/site-packages/django/core/management/commands/test.py", line 26, in run_from_argv
    super().run_from_argv(argv)
  File "/home/vagrant/venv/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/vagrant/venv/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/venv/lib/python3.6/site-packages/django/core/management/commands/test.py", line 59, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/vagrant/venv/lib/python3.6/site-packages/green/djangorunner.py", line 124, in run_tests
    result = run(suite, stream, args)
  File "/home/vagrant/venv/lib/python3.6/site-packages/green/runner.py", line 115, in run
    result.addProtoTestResult(proto_test_result)
  File "/home/vagrant/venv/lib/python3.6/site-packages/green/result.py", line 346, in addProtoTestResult
    for test, err in proto_test_result.errors:
AttributeError: 'NoneType' object has no attribute 'errors'
CleanCut commented 6 years ago

@dizballanze I have not been able to reproduce this error. I have been experimenting with:

Can you provide some way to reproduce the error? If you are working on an open source project, I could try that directly. If not, it would be great if you could produce a small django project which simply reproduces the error.

If you could also provide me with your OS and component versions, that may help.

CleanCut commented 6 years ago

Also, what does your config file look like, and where is it located relative to your project?

dizballanze commented 6 years ago

I use packages and Python version as you described above.

Sometimes it raises described above error. In other tries, it raises a bunch of database errors for some of the tests while other tests pass. Some of the errors it raises:

  File "/home/vagrant/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
    return self.cursor.execute(sql)
psycopg2.DatabaseError: SSL error: decryption failed or bad record mac

I managed to fix this by setting ssl = false in postgresql.conf. But why this works with default test runner?

django.db.transaction.TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.

Many of psycopg2.IntegrityError

Ogaday commented 6 years ago

Just a hunch, as I don't know anything about Django, but this has the hallmarks of concurrency errors.

I had similar issues in another project, wherein green would through different errors on different runs, and using python -m unittest instead didn't raise any errors at all. I figured out that it was because I hadn't considered the fact that green uses multiprocessing, and I was accessing the same the resources in different test modules. Could it be the same situation here?

CleanCut commented 6 years ago

It could be the same situation. For systems not designed for concurrent testing (django), I recommend specifying in your green configuration file to use only one process.

processes = 1

Please let me know if that helps. If it does, then I will add that advice to the Django section of the readme.

CleanCut commented 6 years ago

Hmm...if the multiprocessing ended up being the problem, it may be worth adding a feature to Green to auto-detect when it is running under Django and defaulting to 1 process in that case.

dizballanze commented 6 years ago

It works with processes = 1. But it's possible to run tests in parallel since version 1.9 with default Django test runner.

CleanCut commented 6 years ago

Okay, I'll go ahead and close this, then.

dizballanze commented 6 years ago

Maybe green can support parallel tests in new versions of Django? I've tried to set --parallel option of the Django test runner equal to processes from green. It works but some tests still failing with database errors.

CleanCut commented 6 years ago

That would be cool. Does Django have any documentation about how a test runner can interact with Django to support parallel tests?

charlsagente commented 6 years ago

@CleanCut It is possible in the django documentation. https://docs.djangoproject.com/en/2.0/topics/testing/overview/ with the --parallel flag. BTW Thanks I had the same issue and processes=1 solved the issue.

CleanCut commented 6 years ago

@charlsagente Awesome, I'm so glad it solved the problem for you!

Also, thank you for the pointer to the --parallel flag. I created #190 to track making Django integration more pleasant.