kevin1024 / vcrpy

Automatically mock your HTTP interactions to simplify and speed up testing
MIT License
2.72k stars 388 forks source link

How to run tests #769

Closed sbagri closed 12 months ago

sbagri commented 1 year ago

I am trying to clone this package and run tests but not sure how to run it.

On a linux machine, I did https://github.com/kevin1024/vcrpy.git I also installed a virtual environment using virtualenv venv source venv/bin/activate

I saw online that to install all the requirements, we should run pip install -r requirements.txt. However, this code doesn't have a requirements.txt file.

How do I setup the required packages and get all the tests working?

sbagri commented 1 year ago

I ran python3 setup.py install. It looks like it installed something as it the pip list showed

(venv) vcrpy$ pip list
Package    Version
---------- -------
idna       3.4
idna       3.4
multidict  6.0.4
multidict  6.0.4
pip        23.1.2
PyYAML     6.0.1
PyYAML     6.0.1
setuptools 67.8.0
vcrpy      5.1.0
vcrpy      5.1.0
vcrpy      5.1.0
wheel      0.38.4
wrapt      1.15.0
wrapt      1.15.0
yarl       1.9.2
yarl       1.9.2

Not sure why it is showing the packages twice or more.

After that I ran pytest but got this error

$ pytest
========================================================================== test session starts ===========================================================================
platform linux -- Python 3.11.5, pytest-7.2.1, pluggy-1.0.0+repack
rootdir: vcrpy, configfile: pyproject.toml
collected 254 items / 5 errors / 4 skipped                                                                                                                               

================================================================================= ERRORS =================================================================================
__________________________________________________________ ERROR collecting tests/integration/test_httplib2.py ___________________________________________________________
ImportError while importing test module 'vcrpy/tests/integration/test_httplib2.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/integration/test_httplib2.py:5: in <module>
    import pytest_httpbin.certs
E   ModuleNotFoundError: No module named 'pytest_httpbin'
_____________________________________________________ ERROR collecting tests/integration/test_register_persister.py ______________________________________________________
ImportError while importing test module '/vcrpy/tests/integration/test_register_persister.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/integration/test_register_persister.py:11: in <module>
    from vcr.persisters.filesystem import CassetteDecodeError, CassetteNotFoundError, FilesystemPersister
E   ImportError: cannot import name 'CassetteDecodeError' from 'vcr.persisters.filesystem' (/usr/lib/python3/dist-packages/vcr/persisters/filesystem.py)
___________________________________________________________ ERROR collecting tests/integration/test_urllib2.py ___________________________________________________________
ImportError while importing test module 'vcrpy/tests/integration/test_urllib2.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/integration/test_urllib2.py:7: in <module>
    import pytest_httpbin.certs
E   ModuleNotFoundError: No module named 'pytest_httpbin'
___________________________________________________________ ERROR collecting tests/integration/test_urllib3.py ___________________________________________________________
ImportError while importing test module '/vcrpy/tests/integration/test_urllib3.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/integration/test_urllib3.py:6: in <module>
    import pytest_httpbin
E   ModuleNotFoundError: No module named 'pytest_httpbin'
______________________________________________________________ ERROR collecting tests/unit/test_unittest.py ______________________________________________________________
ImportError while importing test module 'vcrpy/tests/unit/test_unittest.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/unit/test_unittest.py:8: in <module>
    from vcr.unittest import VCRTestCase
E   ModuleNotFoundError: No module named 'vcr.unittest'
======================================================================== short test summary info =========================================================================
ERROR tests/integration/test_httplib2.py
ERROR tests/integration/test_register_persister.py
ERROR tests/integration/test_urllib2.py
ERROR tests/integration/test_urllib3.py
ERROR tests/unit/test_unittest.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 5 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
====================================================================== 4 skipped, 5 errors in 0.28s ======================================================================
hartwork commented 12 months ago

@sbagri I think you are looking for tox. This is how the tests are run in CI using tox:

https://github.com/kevin1024/vcrpy/blob/c062c9f54c5d8577aba5a16820627171c1016acb/.github/workflows/main.yml#L31-L40

The related config file tox.ini tells tox what to do. To only run a subset of all the so-called environments, you could use tox list to list the environemnts and then add -e env1,env2,env3 when calling tox.

I'll close this as "question answered" but please don't read that as a silencer and we can also re-open as needed.