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

Running unit tests #105

Closed
daym opened this issue May 25, 2017 · 7 comments
Closed

Running unit tests #105

daym opened this issue May 25, 2017 · 7 comments

Comments

@daym
Copy link
Contributor

daym commented May 25, 2017

We are trying to package flasgger in the Guix distribution. There, we usually run the unit tests before installation.

How should we do that for flasgger?

@rochacbruno
Copy link
Member

pip install -r requirements.txt

then

make test

or

py.test tests

@daym
Copy link
Contributor Author

daym commented May 26, 2017

Yeah, using the github release the tests run (P.S. requirements.txt and Makefile not included in the PyPI release), but I get:

flasgger/base.py:24:1: E731 do not assign a lambda expression, use a def
flasgger/base.py:25:1: E731 do not assign a lambda expression, use a def
flasgger/base.py:26:1: E731 do not assign a lambda expression, use a def
flasgger/marshmallow_apispec.py:17:5: E731 do not assign a lambda expression, use a def
flasgger/marshmallow_apispec.py:18:5: E731 do not assign a lambda expression, use a def

@daym
Copy link
Contributor Author

daym commented May 26, 2017

After manually adding --ignore=E731 to the Makefile, I get:

Traceback (most recent call last):
  File "/gnu/store/37vxs78h32r7z4h0q42q1sd9jkf0dssj-python-pytest-2.7.3/lib/python3.5/site-packages/_pytest/config.py", line 516, in getconftestmodules
    return self._path2confmods[path]
KeyError: local('/tmp/guix-build-python-flasgger-0.6.3.drv-0/flasgger-0.6.3/tests')

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/gnu/store/37vxs78h32r7z4h0q42q1sd9jkf0dssj-python-pytest-2.7.3/lib/python3.5/site-packages/_pytest/config.py", line 540, in importconftest
    return self._conftestpath2mod[conftestpath]
KeyError: local('/tmp/guix-build-python-flasgger-0.6.3.drv-0/flasgger-0.6.3/tests/conftest.py')

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/gnu/store/37vxs78h32r7z4h0q42q1sd9jkf0dssj-python-pytest-2.7.3/lib/python3.5/site-packages/_pytest/config.py", line 546, in importconftest
    mod = conftestpath.pyimport()
  File "/gnu/store/s7n625jx3zd4ia2sabfc4kxwzkgx9n17-python-py-1.4.32/lib/python3.5/site-packages/py/_path/local.py", line 662, in pyimport
    __import__(modname)
  File "/tmp/guix-build-python-flasgger-0.6.3.drv-0/flasgger-0.6.3/tests/conftest.py", line 4, in <module>
    from flasgger import Swagger
ImportError: No module named 'flasgger'
ERROR: could not load /tmp/guix-build-python-flasgger-0.6.3.drv-0/flasgger-0.6.3/tests/conftest.py

@daym
Copy link
Contributor Author

daym commented May 27, 2017

After manually amending PYTHONPATH, I get:

$ make test
============================= test session starts ==============================
platform linux -- Python 3.5.3 -- py-1.4.32 -- pytest-2.7.3 -- /gnu/store/bf54hnwd8mb63zmssc23fwslf5zvxpxs-python-wrapper-3.5.3/bin/python
rootdir: /tmp/guix-build-python-flasgger-0.6.3.drv-0/flasgger-0.6.3, inifile: 
plugins: cov
collecting ... collected 0 items / 2 errors

==================================== ERRORS ====================================
_____________ ERROR collecting examples/definition_object_test.py ______________
import file mismatch:
imported module 'examples.definition_object_test' has this __file__ attribute:
  /tmp/guix-build-python-flasgger-0.6.3.drv-0/flasgger-0.6.3/build/lib/examples/definition_object_test.py
which is not the same as the test file we want to collect:
  /tmp/guix-build-python-flasgger-0.6.3.drv-0/flasgger-0.6.3/examples/definition_object_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
___________________ ERROR collecting tests/test_examples.py ____________________
tests/conftest.py:39: in pytest_generate_tests
    for mod in get_examples()
flasgger/utils.py:263: in get_examples
    modules = [import_module(module) for module in pathify(basenames)]
flasgger/utils.py:263: in <listcomp>
    modules = [import_module(module) for module in pathify(basenames)]
/gnu/store/3aw9x28la9nh8fzkm665d7fywxzbl15j-python-3.5.3/lib/python3.5/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:986: in _gcd_import
    ???
<frozen importlib._bootstrap>:969: in _find_and_load
    ???
<frozen importlib._bootstrap>:958: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:673: in _load_unlocked
    ???
<frozen importlib._bootstrap_external>:673: in exec_module
    ???
<frozen importlib._bootstrap>:222: in _call_with_frames_removed
    ???
build/lib/examples/marshmallow_apispec.py:19: in <module>
    class User(Schema):
build/lib/examples/marshmallow_apispec.py:20: in User
    username = fields.Str(required=True)
E   AttributeError: 'NoneType' object has no attribute 'Str'

----------- coverage: platform linux, python 3.5.3-final-0 -----------
Name                              Stmts   Miss  Cover
-----------------------------------------------------
flasgger/__init__.py                  7      0   100%
flasgger/base.py                    189    117    38%
flasgger/constants.py                 1      0   100%
flasgger/marshmallow_apispec.py      61     37    39%
flasgger/utils.py                   271    208    23%
-----------------------------------------------------
TOTAL                               529    362    32%

=========================== 2 error in 0.84 seconds ============================
make: *** [Makefile:11: test] Error 1

Trying with pytest 3.0, I get instead:

============================= test session starts ==============================
platform linux -- Python 3.5.3, pytest-3.0.7, py-1.4.32, pluggy-0.4.0 -- /gnu/store/bf54hnwd8mb63zmssc23fwslf5zvxpxs-python-wrapper-3.5.3/bin/python
cachedir: .cache
rootdir: /tmp/guix-build-python-flasgger-0.6.3.drv-0/flasgger-0.6.3, inifile:
plugins: hypothesis-3.1.0, cov-2.4.0
collecting ... collected 0 items / 1 errors


----------- coverage: platform linux, python 3.5.3-final-0 -----------
Name                              Stmts   Miss  Cover
-----------------------------------------------------
flasgger/__init__.py                  7      0   100%
flasgger/base.py                    189    117    38%
flasgger/constants.py                 1      0   100%
flasgger/marshmallow_apispec.py      61     37    39%
flasgger/utils.py                   271    208    23%
-----------------------------------------------------
TOTAL                               529    362    32%

==================================== ERRORS ====================================
___________________ ERROR collecting tests/test_examples.py ____________________
tests/conftest.py:39: in pytest_generate_tests
    for mod in get_examples()
flasgger/utils.py:263: in get_examples
    modules = [import_module(module) for module in pathify(basenames)]
flasgger/utils.py:263: in <listcomp>
    modules = [import_module(module) for module in pathify(basenames)]
/gnu/store/3aw9x28la9nh8fzkm665d7fywxzbl15j-python-3.5.3/lib/python3.5/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:986: in _gcd_import
    ???
<frozen importlib._bootstrap>:969: in _find_and_load
    ???
<frozen importlib._bootstrap>:958: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:673: in _load_unlocked
    ???
<frozen importlib._bootstrap_external>:673: in exec_module
    ???
<frozen importlib._bootstrap>:222: in _call_with_frames_removed
    ???
examples/marshmallow_apispec.py:19: in <module>
    class User(Schema):
examples/marshmallow_apispec.py:20: in User
    username = fields.Str(required=True)
E   AttributeError: 'NoneType' object has no attribute 'Str'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.94 seconds ============================
make: *** [Makefile:11: test] Error 2

@daym
Copy link
Contributor Author

daym commented Jun 3, 2017

This happens when apispec cannot be imported (because it cannot be found because we forgot to provide it). So this issue is not so bad. It would still be nice to improve the error reporting so one can actually see why that is.

@javabrett
Copy link
Collaborator

Tests are running nicely for me in a Docker image I build for flasgger, which runs pip3 -r on the two requirements files, then make test. Will add a PR for the Docker image sometime.

----------- coverage: platform linux, python 3.6.6-final-0 -----------
Name                              Stmts   Miss  Cover
-----------------------------------------------------
flasgger/__init__.py                  8      0   100%
flasgger/base.py                    252     18    93%
flasgger/constants.py                 1      0   100%
flasgger/marshmallow_apispec.py      68      1    99%
flasgger/utils.py                   409     51    88%
-----------------------------------------------------
TOTAL                               738     70    91%

Based on that I'm closing this issue - @daym please reopen if it's unclear how to run the tests.

@Lounarok
Copy link
Contributor

Lounarok commented Nov 8, 2021

For new comers.
Before make test, you need pip install -r requirements-dev.txt

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

No branches or pull requests

4 participants