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

test case issues #132

Closed
claytondaley opened this issue Dec 27, 2020 · 7 comments · Fixed by #136
Closed

test case issues #132

claytondaley opened this issue Dec 27, 2020 · 7 comments · Fixed by #136

Comments

@claytondaley
Copy link
Contributor

I've tried both PyCharm and the command line (from readme) to run the tox tests. I'm running into (at least) two issues:

  1. PyTest complains about six (No module named 'six') which I can resolve by adding six to requirements.txt
  2. All of the tests fail with no such table: ...

I think I've seen something similar when tests have been run without the Django extension, but I'm confused why the documented process isn't working.

@kiancm
Copy link

kiancm commented Jan 11, 2021

I setup a virtual environment with pyenv and poetry and managed to get this test report on your fork on the new-style-serializers branch:

GLOB sdist-make: /home/sync/src/drf-writable-nested/setup.py
py37-dj22-drf38 inst-nodeps: /home/sync/src/drf-writable-nested/.tox/.tmp/package/1/drf-writable-nested-0.5.4.zip
py37-dj22-drf38 installed: /home/sync/src/drf-writable-nested/.tox/py37-dj22-drf38/lib/python3.7/site-packages/pip/_vendor/packaging/version.py:130: DeprecationWarning: Creating a LegacyVersion has been deprecated and will be removed in the next major release,  DeprecationWarning,,appdirs==1.4.4,atomicwrites==1.4.0,attrs==20.3.0,coverage==5.3.1,distlib==0.3.1,Django==2.2.17,djangorestframework==3.8.2,drf-writable-nested @ file:///home/sync/src/drf-writable-nested/.tox/.tmp/package/1/drf-writable-nested-0.5.4.zip,filelock==3.0.12,importlib-metadata==3.4.0,more-itertools==8.6.0,packaging==20.8,pluggy==0.13.1,py==1.10.0,pyparsing==2.4.7,pytest==4.4.0,pytest-cov==2.6.1,pytest-django==3.4.8,pytz==2020.5,six==1.15.0,sqlparse==0.4.1,toml==0.10.2,tox==3.21.0,typing-extensions==3.7.4.3,virtualenv==20.3.0,zipp==3.4.0
py37-dj22-drf38 run-test-pre: PYTHONHASHSEED='1270612429'
py37-dj22-drf38 run-test: commands[0] | ./py.test --cov drf_writable_nested
/home/sync/src/drf-writable-nested/.tox/py37-dj22-drf38/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:8: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
/home/sync/src/drf-writable-nested/.tox/py37-dj22-drf38/lib/python3.7/site-packages/_pytest/mark/structures.py:350: DeprecationWarning: The usage of `cmp` is deprecated and will be removed on or after 2021-06-01.  Please use `eq` and `order` instead.
  @attr.s(cmp=False, hash=False)
============================================= test session starts ==============================================
platform linux -- Python 3.7.9, pytest-4.4.0, py-1.10.0, pluggy-0.13.1
cachedir: .tox/py37-dj22-drf38/.pytest_cache
rootdir: /home/sync/src/drf-writable-nested, inifile: tox.ini
plugins: cov-2.6.1, django-3.4.8
collected 89 items                                                                                             

tests/test_field_lookup.py ..............                                                                [ 15%]
tests/test_nested_serializer_mixins.py .............F...                                                 [ 34%]
tests/test_nested_validation.py ......                                                                   [ 41%]
tests/test_unique_fields_mixin.py ..                                                                     [ 43%]
tests/test_writable_nested_model_serializer.py .........................                                 [ 71%]
tests/test_writable_nested_model_serializer_converted.py ........F.....FFFF.....F.                       [100%]

=================================================== FAILURES ===================================================
___________________________ CreateOnlyModelSerializerTest.test_create_despite_match ____________________________
tests/test_nested_serializer_mixins.py:576: in test_create_despite_match
    serializer.save()
drf_writable_nested/mixins.py:554: in save
    self._save_direct_relations(kwargs=kwargs)
drf_writable_nested/mixins.py:575: in _save_direct_relations
    self._validated_data[field.source] = field.save(**kwargs.pop(field_name, {}))
drf_writable_nested/mixins.py:555: in save
    instance = super(RelatedSaveMixin, self).save(**kwargs)
../../.pyenv/versions/3.7.9/lib/python3.7/contextlib.py:74: in inner
    return func(*args, **kwds)
drf_writable_nested/mixins.py:697: in save
    match, needs_saved = self.match(kwargs)
drf_writable_nested/mixins.py:936: in match
    raise IntegrityError("Matching {} object already exists".format(match.__class__.__name__))
E   django.db.utils.IntegrityError: Matching Child object already exists
_____________________ WritableNestedModelSerializerTest.test_create_with_generic_relation ______________________
tests/test_writable_nested_model_serializer_converted.py:114: in test_create_with_generic_relation
    serializer.is_valid(raise_exception=True)
.tox/py37-dj22-drf38/lib/python3.7/site-packages/rest_framework/serializers.py:236: in is_valid
    self._validated_data = self.run_validation(self.initial_data)
drf_writable_nested/mixins.py:518: in run_validation
    self._validated_data = super(RelatedSaveMixin, self).run_validation(data)
.tox/py37-dj22-drf38/lib/python3.7/site-packages/rest_framework/serializers.py:434: in run_validation
    value = self.to_internal_value(data)
drf_writable_nested/mixins.py:525: in to_internal_value
    self._make_reverse_relations_valid()
drf_writable_nested/mixins.py:531: in _make_reverse_relations_valid
    if self.field_types[field_name] != self.TYPE_REVERSE:
drf_writable_nested/mixins.py:474: in field_types
    self._populate_field_types()
drf_writable_nested/mixins.py:482: in _populate_field_types
    raise TypeError("GenericRelation not currently supported")
E   TypeError: GenericRelation not currently supported
_________________________ WritableNestedModelSerializerTest.test_nested_partial_update _________________________
tests/test_writable_nested_model_serializer_converted.py:525: in test_nested_partial_update
    'key': 'new',
drf_writable_nested/mixins.py:798: in __init__
    raise ValueError("Partial Updates not currently supported by NestedSaveSerializer")
E   ValueError: Partial Updates not currently supported by NestedSaveSerializer
_______ WritableNestedModelSerializerTest.test_nested_partial_update_failed_with_empty_direct_fk_object ________
tests/test_writable_nested_model_serializer_converted.py:574: in test_nested_partial_update_failed_with_empty_direct_fk_object
    'user_avatar': {},
drf_writable_nested/mixins.py:798: in __init__
    raise ValueError("Partial Updates not currently supported by NestedSaveSerializer")
E   ValueError: Partial Updates not currently supported by NestedSaveSerializer
____________________________ WritableNestedModelSerializerTest.test_partial_update _____________________________
tests/test_writable_nested_model_serializer_converted.py:416: in test_partial_update
    'username': 'new',
drf_writable_nested/mixins.py:798: in __init__
    raise ValueError("Partial Updates not currently supported by NestedSaveSerializer")
E   ValueError: Partial Updates not currently supported by NestedSaveSerializer
_______________________ WritableNestedModelSerializerTest.test_partial_update_direct_fk ________________________
tests/test_writable_nested_model_serializer_converted.py:475: in test_partial_update_direct_fk
    'key': 'new',
drf_writable_nested/mixins.py:798: in __init__
    raise ValueError("Partial Updates not currently supported by NestedSaveSerializer")
E   ValueError: Partial Updates not currently supported by NestedSaveSerializer
_____________________ WritableNestedModelSerializerTest.test_update_with_generic_relation ______________________
tests/test_writable_nested_model_serializer_converted.py:591: in test_update_with_generic_relation
    serializer.is_valid(raise_exception=True)
.tox/py37-dj22-drf38/lib/python3.7/site-packages/rest_framework/serializers.py:236: in is_valid
    self._validated_data = self.run_validation(self.initial_data)
drf_writable_nested/mixins.py:518: in run_validation
    self._validated_data = super(RelatedSaveMixin, self).run_validation(data)
.tox/py37-dj22-drf38/lib/python3.7/site-packages/rest_framework/serializers.py:434: in run_validation
    value = self.to_internal_value(data)
drf_writable_nested/mixins.py:525: in to_internal_value
    self._make_reverse_relations_valid()
drf_writable_nested/mixins.py:531: in _make_reverse_relations_valid
    if self.field_types[field_name] != self.TYPE_REVERSE:
drf_writable_nested/mixins.py:474: in field_types
    self._populate_field_types()
drf_writable_nested/mixins.py:482: in _populate_field_types
    raise TypeError("GenericRelation not currently supported")
E   TypeError: GenericRelation not currently supported
=============================================== warnings summary ===============================================
.tox/py37-dj22-drf38/lib/python3.7/site-packages/rest_framework/serializers.py:18
  /home/sync/src/drf-writable-nested/.tox/py37-dj22-drf38/lib/python3.7/site-packages/rest_framework/serializers.py:18: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
    from collections import Mapping, OrderedDict

.tox/py37-dj22-drf38/lib/python3.7/site-packages/rest_framework/utils/serializer_helpers.py:133
  /home/sync/src/drf-writable-nested/.tox/py37-dj22-drf38/lib/python3.7/site-packages/rest_framework/utils/serializer_helpers.py:133: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
    class BindingDict(collections.MutableMapping):

-- Docs: https://docs.pytest.org/en/latest/warnings.html

----------- coverage: platform linux, python 3.7.9-final-0 -----------
Name                                 Stmts   Miss  Cover
--------------------------------------------------------
drf_writable_nested/__init__.py          8      0   100%
drf_writable_nested/mixins.py          548     30    95%
drf_writable_nested/serializers.py       4      0   100%
--------------------------------------------------------
TOTAL                                  560     30    95%

=============================== 7 failed, 82 passed, 2 warnings in 4.86 seconds ================================
ERROR: InvocationError for command /home/sync/src/drf-writable-nested/.tox/py37-dj22-drf38/bin/py.test --cov drf_writable_nested (exited with code 1)
___________________________________________________ summary ____________________________________________________
ERROR:   py37-dj22-drf38: commands failed

Let me know if you want to see my environment configuration 📦

@ruscoder
Copy link
Member

ruscoder commented Feb 1, 2021

@claytondaley I'll take a look at why tests are not running and give you a suggestion.

@ruscoder
Copy link
Member

ruscoder commented Feb 1, 2021

@claytondaley I think we had the wrong description about running tests locally, because tox is usually used on CI.

So, I've updated the instruction about running tests in README.md.

# Setup the virtual environment
python3 -m venv envname
source envname/bin/activate

pip install django
pip install django-rest-framework
pip install -r requirements.txt

# Run tests
py.test

@ruscoder ruscoder closed this as completed Feb 1, 2021
@claytondaley
Copy link
Contributor Author

claytondaley commented Feb 1, 2021

OK. Operator error. I had models outside models.py (i.e. in a test file) which apparently works using django testing but maybe not pytest, I continue to have an issue (in pytest_django\live_server_helper.py) if I don't include six in requirements.txt.

@ruscoder ruscoder reopened this Feb 8, 2021
@ruscoder
Copy link
Member

ruscoder commented Feb 8, 2021

@claytondaley It's very strange because six isn't used anymore in Django and DRF since dropping python2. Maybe you have previous versions installed?

@ruscoder
Copy link
Member

ruscoder commented Feb 8, 2021

@claytondaley Try to update python-django version to the latest

@claytondaley
Copy link
Contributor Author

claytondaley commented Feb 8, 2021

I'm actually running a tox test through PyCharm on Windows -- py36-dj31-drf311-pytest which is valid:

    py{36,37,38}-dj{31}-drf{311}-{pytest,mypy}

The requirements.txt file asks for pytest-django==3.9.0 which uses six in live_server_helper.py. pytest-django drops support for Python <3.5 in v4.0 so the import also goes away. I (re)tested the tox run with:

pytest-django==4.0.0

... and it works so I'll PR that change so we can verify it doesn't break other environments.

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 a pull request may close this issue.

3 participants