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

Add testing for current Django versions #200

Merged
merged 9 commits into from
May 12, 2020
Merged

Conversation

ipmb
Copy link
Contributor

@ipmb ipmb commented Jan 28, 2020

refs #10 #85

Description of changes:

Update tox so it will test against currently supported versions of Django.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-io
Copy link

codecov-io commented Jan 28, 2020

Codecov Report

Merging #200 into master will decrease coverage by 5.65%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #200      +/-   ##
==========================================
- Coverage   83.92%   78.26%   -5.66%     
==========================================
  Files          77       77              
  Lines        3004     3004              
==========================================
- Hits         2521     2351     -170     
- Misses        483      653     +170
Impacted Files Coverage Δ
aws_xray_sdk/ext/django/__init__.py 0% <0%> (-100%) ⬇️
aws_xray_sdk/ext/django/templates.py 0% <0%> (-90%) ⬇️
aws_xray_sdk/ext/django/conf.py 0% <0%> (-87.5%) ⬇️
aws_xray_sdk/ext/django/middleware.py 0% <0%> (-87.28%) ⬇️
aws_xray_sdk/ext/django/db.py 0% <0%> (-72.31%) ⬇️
aws_xray_sdk/ext/django/apps.py 0% <0%> (-67.86%) ⬇️
aws_xray_sdk/ext/dbapi2.py 80.85% <0%> (-8.52%) ⬇️
aws_xray_sdk/core/recorder.py 85.71% <0%> (-1.75%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b47f1e8...1318b15. Read the comment docs.

@ipmb
Copy link
Contributor Author

ipmb commented Jan 28, 2020

All the Django tests have the following failure:

$ pytest tests/ext/django
========================================================================================== test session starts ==========================================================================================
platform linux -- Python 3.6.9, pytest-5.3.4, py-1.8.1, pluggy-0.13.1
rootdir: /app
collected 14 items                                                                                                                                                                                      

tests/ext/django/test_db.py ....                                                                                                                                                                  [ 28%]
tests/ext/django/test_middleware.py F.........                                                                                                                                                    [100%]

=============================================================================================== FAILURES ================================================================================================
_________________________________________________________________________________________ XRayTestCase.test_db __________________________________________________________________________________________

self = <app.tests.ext.django.test_middleware.XRayTestCase testMethod=test_db>

    def test_db(self):
        url = reverse('call_db')
        self.client.get(url)
        segment = xray_recorder.emitter.pop()
>       assert len(segment.subsegments) == 1
E       AssertionError: assert 0 == 1
E        +  where 0 = len([])
E        +    where [] = <aws_xray_sdk.core.models.segment.Segment object at 0x7fc72d5c1518>.subsegments

tests/ext/django/test_middleware.py:72: AssertionError
------------------------------------------------------------------------------------------ Captured log setup -------------------------------------------------------------------------------------------
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
WARNING  aws_xray_sdk.core.recorder:recorder.py:286 No segment found, cannot begin subsegment execute.
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
------------------------------------------------------------------------------------------- Captured log call -------------------------------------------------------------------------------------------
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
WARNING  aws_xray_sdk.core.recorder:recorder.py:286 No segment found, cannot begin subsegment execute.
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
WARNING  aws_xray_sdk.core.recorder:recorder.py:286 No segment found, cannot begin subsegment execute.
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
WARNING  aws_xray_sdk.core.recorder:recorder.py:286 No segment found, cannot begin subsegment execute.
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
=========================================================================================== warnings summary ============================================================================================
/usr/local/lib/python3.6/site-packages/_pytest/mark/structures.py:327
  /usr/local/lib/python3.6/site-packages/_pytest/mark/structures.py:327: PytestUnknownMarkWarning: Unknown pytest.mark.django_db - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
    PytestUnknownMarkWarning,

tests/ext/django/test_db.py::test_all[False]
  /usr/local/lib/python3.6/site-packages/django/contrib/auth/base_user.py:52: DeprecationWarning: __class__ not set defining 'AbstractBaseUser' as <class 'django.contrib.auth.base_user.AbstractBaseUser'>. Was __classcell__ propagated to type.__new__?
    class AbstractBaseUser(models.Model):

-- Docs: https://docs.pytest.org/en/latest/warnings.html
=============================================================================== 1 failed, 13 passed, 2 warnings in 1.05s ================================================================================

I'm seeing this even on environments that should be supported (Python 3.6, Django 1.10 and 1.11). I'm familiar with Django, but not with the xray sdk. If a maintainer can point me in the right direction, I'm happy to try to fix this issue.

@willarmiros
Copy link
Contributor

Hi @ipmb,
Thank you very much for your contribution. We'll be sure to give the changes a review as soon as possible and see what may be causing these segment missing errors.

@bhautikpip
Copy link
Contributor

bhautikpip commented Feb 24, 2020

Hi @ipmb ,

Is this the(#200 (comment)) snippet of your local machine error? I think Travis CI is passing fine for other PRs (#204) . So it means Django tests passes with Django (1.10 and 1.11 and python 3.6)

@ipmb
Copy link
Contributor Author

ipmb commented Feb 25, 2020

Thanks for the tip @bhautikpip. I'm seeing the errors both locally and on Travis. It looks like the issue is that the tests fail when only run against tests/ext/django. For example:

coverage run --source aws_xray_sdk -m py.test tests/ext/django

I see this on both this branch and master.

In order to test against the different Django versions, I'm trying to isolate the Django-specific tests so we can run them in their own tox environments. Could you suggest a way to run just the django tests?

@bhautikpip
Copy link
Contributor

bhautikpip commented Feb 28, 2020

I don't see any reason why tests fails when running against tests/ext/django. I think the command (coverage run --source aws_xray_sdk -m py.test tests/ext/django) you have posted should be good for running Django specific tests and will run all the django specific tests or you can utilize IDE capabilities to run a single test.

@ipmb
Copy link
Contributor Author

ipmb commented Feb 28, 2020

Here's a minimal Dockerfile that exhibits the issue I'm seeing (this is on master):

FROM python:3.7
WORKDIR /app
ENV DJANGO_SETTINGS_MODULE=tests.ext.django.app.settings
COPY . .
RUN pip install -e . pytest 'django>=1.10,<2.0' django-fake-model
CMD pytest tests/ext/django

If you run this, you'll get the same error:

$ docker build -t xray . && docker run xray
# ... build details ...
============================= test session starts ==============================
platform linux -- Python 3.7.4, pytest-5.3.5, py-1.8.1, pluggy-0.13.1
rootdir: /app
collected 14 items

tests/ext/django/test_db.py ....                                         [ 28%]
tests/ext/django/test_middleware.py F.........                           [100%]

=================================== FAILURES ===================================
_____________________________ XRayTestCase.test_db _____________________________

self = <app.tests.ext.django.test_middleware.XRayTestCase testMethod=test_db>

>   ???
E   AssertionError: assert 0 == 1
E    +  where 0 = len([])
E    +    where [] = <aws_xray_sdk.core.models.segment.Segment object at 0x7f9919282990>.subsegments

/srv/share/projects/aws-xray-sdk-python/tests/ext/django/test_middleware.py:72: AssertionError
------------------------------ Captured log setup ------------------------------
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
WARNING  aws_xray_sdk.core.recorder:recorder.py:286 No segment found, cannot begin subsegment execute.
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
------------------------------ Captured log call -------------------------------
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
WARNING  aws_xray_sdk.core.recorder:recorder.py:286 No segment found, cannot begin subsegment execute.
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
WARNING  aws_xray_sdk.core.recorder:recorder.py:286 No segment found, cannot begin subsegment execute.
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
WARNING  aws_xray_sdk.core.recorder:recorder.py:286 No segment found, cannot begin subsegment execute.
ERROR    aws_xray_sdk.core.context:context.py:120 cannot find the current segment/subsegment, please make sure you have a segment open
=============================== warnings summary ===============================
/usr/local/lib/python3.7/site-packages/_pytest/mark/structures.py:327
  /usr/local/lib/python3.7/site-packages/_pytest/mark/structures.py:327: PytestUnknownMarkWarning: Unknown pytest.mark.django_db - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
    PytestUnknownMarkWarning,

/usr/local/lib/python3.7/site-packages/django/db/models/sql/query.py:11
/usr/local/lib/python3.7/site-packages/django/db/models/sql/query.py:11
  /usr/local/lib/python3.7/site-packages/django/db/models/sql/query.py:11: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    from collections import Counter, Iterator, Mapping, OrderedDict

tests/ext/django/test_middleware.py:3
  /app/tests/ext/django/test_middleware.py:3: RemovedInDjango20Warning: Importing from django.core.urlresolvers is deprecated in favor of django.urls.
    from django.core.urlresolvers import reverse

/usr/local/lib/python3.7/site-packages/django/core/paginator.py:126
  /usr/local/lib/python3.7/site-packages/django/core/paginator.py:126: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
    class Page(collections.Sequence):

-- Docs: https://docs.pytest.org/en/latest/warnings.html
=================== 1 failed, 13 passed, 5 warnings in 1.05s ===================

@ipmb ipmb force-pushed the django-versions branch 4 times, most recently from 329ab77 to fef67e2 Compare March 2, 2020 05:53
@ipmb
Copy link
Contributor Author

ipmb commented Mar 2, 2020

Found the issue, there was a patch happening in the sqlite3 test module in the global scope. I moved it out of the global scope and applied it to the Django test that was failing in dfdb8fd.

Some tests are failing, but I expect that #206 and #205 resolve those.

ipmb added 2 commits March 1, 2020 23:09
Previously the patch was global which caused the django tests to fail if
the sqlite3 tests weren't also run.
@ipmb ipmb force-pushed the django-versions branch from fef67e2 to 29c4f71 Compare March 2, 2020 06:09
@@ -44,7 +44,6 @@
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we remove this 'django.contrib.auth.middleware.SessionAuthenticationMiddleware' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SessionAuthenticationMiddleware class is removed. It provided no functionality since session authentication is unconditionally enabled in Django 1.10.

https://docs.djangoproject.com/en/2.0/releases/2.0/#miscellaneous

@bhautikpip
Copy link
Contributor

Would you mind resolving the conflict ? This should be good to go!

@ipmb
Copy link
Contributor Author

ipmb commented Mar 26, 2020

@bhautikpip The merge conflict is resolved.

@srprash
Copy link
Contributor

srprash commented May 11, 2020

Hi @ipmb
We got the support for latest versions of Django merged with this PR. If this PR only aims to do that, can we close it out?
Thanks!

@ipmb
Copy link
Contributor Author

ipmb commented May 11, 2020

#206 adds support in the code.
This PR actually executes the test suite against the versions that are supported. Django can have breaking changes between different versions (1.11, 2.2, 3.0) so testing each version individually is a good idea to verify compatibility.

@srprash
Copy link
Contributor

srprash commented May 12, 2020

Okay. I see. Thanks for clarifying!

@srprash srprash merged commit eda0c89 into aws:master May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants