Skip to content

Commit

Permalink
Run tests without tox
Browse files Browse the repository at this point in the history
  • Loading branch information
jairhenrique committed Dec 11, 2023
1 parent dd97b02 commit 31a8a72
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 145 deletions.
32 changes: 19 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,20 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.8", "pypy-3.9", "pypy-3.10"]
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "pypy-3.8"
- "pypy-3.9"
- "pypy-3.10"
urllib3-requirement: "urllib3>=2"

include:
- python-version: ["3.10", "3.11", "3.12"]
urllib3-requirement: "urllib3<2"

steps:
- uses: actions/checkout@v4
Expand All @@ -22,22 +35,15 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip

- name: Install project dependencies
run: |
pip3 install --upgrade pip
pip3 install codecov tox tox-gh-actions
pip install --upgrade pip
pip install codecov .[tests] '${{ matrix.urllib3-requirement }}'
- name: Run online tests with tox
run: tox -- -m online

- name: Run offline tests with tox with no access to the Internet
run: |
# We're using unshare to take Internet access
# away from tox so that we'll notice whenever some new test
# is missing @pytest.mark.online decoration in the future
unshare --map-root-user --net -- \
sh -c 'ip link set lo up; tox -- -m "not online"'
- name: Run tests
run: ./runtests.sh --cov=./vcr --cov-branch --cov-report=xml --cov-append

- name: Run coverage
run: codecov
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
include README.rst
include LICENSE.txt
include tox.ini
recursive-include tests *
recursive-exclude * __pycache__
recursive-exclude * *.py[co]
43 changes: 10 additions & 33 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,21 @@ The PR reviewer is a second set of eyes to see if:
Running VCR's test suite
------------------------

The tests are all run automatically on `Travis
CI <https://travis-ci.org/kevin1024/vcrpy>`__, but you can also run them
yourself using `pytest <http://pytest.org/>`__ and
`Tox <http://tox.testrun.org/>`__.
The tests are all run automatically on `Github Actions CI <https://github.com/kevin1024/vcrpy/actions>`__,
but you can also run them yourself using `pytest <http://pytest.org/>`__.

Tox will automatically run them in all environments VCR.py supports if they are available on your `PATH`. Alternatively you can use `tox-pyenv <https://pypi.org/project/tox-pyenv/>`_ with
`pyenv <https://github.com/pyenv/pyenv>`_.
We recommend you read the documentation for each and see the section further below.

The test suite is pretty big and slow, but you can tell tox to only run specific tests like this::

tox -e {pyNN}-{HTTP_LIBRARY} -- <pytest flags passed through>

tox -e py38-requests -- -v -k "'test_status_code or test_gzip'"
tox -e py38-requests -- -v --last-failed

This will run only tests that look like ``test_status_code`` or
``test_gzip`` in the test suite, and only in the python 3.8 environment
that has ``requests`` installed.

Also, in order for the boto3 tests to run, you will need an AWS key.
In order for the boto3 tests to run, you will need an AWS key.
Refer to the `boto3
documentation <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/index.html>`__
for how to set this up. I have marked the boto3 tests as optional in
Travis so you don't have to worry about them failing if you submit a
pull request.

Using PyEnv with VCR's test suite
Using Pyenv with VCR's test suite
---------------------------------

PyEnv is a tool for managing multiple installation of python on your system.
Pyenv is a tool for managing multiple installation of python on your system.
See the full documentation at their `github <https://github.com/pyenv/pyenv>`_
but we are also going to use `tox-pyenv <https://pypi.org/project/tox-pyenv/>`_
in this example::

git clone https://github.com/pyenv/pyenv ~/.pyenv
Expand All @@ -126,26 +108,21 @@ in this example::
# Setup shim paths
eval "$(pyenv init -)"

# Setup your local system tox tooling
pip3 install tox tox-pyenv

# Install supported versions (at time of writing), this does not activate them
pyenv install 3.8.0 pypy3.8
pyenv install 3.12.0 pypy3.10

# This activates them
pyenv local 3.8.0 pypy3.8
pyenv local 3.12.0 pypy3.10

# Run the whole test suite
tox

# Run the whole test suite or just part of it
tox -e py38-requests
pip install .[test]
./run_tests.sh


Troubleshooting on MacOSX
-------------------------

If you have this kind of error when running tox :
If you have this kind of error when running tests :

.. code:: python
Expand Down
43 changes: 24 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,29 @@ def run_tests(self):
"urllib3 <2; platform_python_implementation =='PyPy'",
]

tests_require = [
"aiohttp",
"boto3",
"httplib2",
"httpx",
"pytest",
"pytest-aiohttp",
"pytest-httpbin",
"requests>=2.16.2",
"tornado",
# Needed to un-break httpbin 0.7.0. For httpbin >=0.7.1 and after,
# this pin and the dependency itself can be removed, provided
# that the related bug in httpbin has been fixed:
# https://github.com/kevin1024/vcrpy/issues/645#issuecomment-1562489489
# https://github.com/postmanlabs/httpbin/issues/673
# https://github.com/postmanlabs/httpbin/pull/674
"Werkzeug==2.0.3",
]
tests_require = {
"tests": [
"aiohttp",
"boto3",
"httplib2",
"httpx",
"pytest-aiohttp",
"pytest-asyncio",
"pytest-cov",
"pytest-httpbin",
"pytest",
"requests>=2.22.0",
"tornado",
"urllib3",
# Needed to un-break httpbin 0.7.0. For httpbin >=0.7.1 and after,
# this pin and the dependency itself can be removed, provided
# that the related bug in httpbin has been fixed:
# https://github.com/kevin1024/vcrpy/issues/645#issuecomment-1562489489
# https://github.com/postmanlabs/httpbin/issues/673
# https://github.com/postmanlabs/httpbin/pull/674
"Werkzeug==2.0.3",
],
}

setup(
name="vcrpy",
Expand All @@ -89,7 +94,7 @@ def run_tests(self):
python_requires=">=3.8",
install_requires=install_requires,
license="MIT",
tests_require=tests_require,
extras_require=tests_require,
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,18 @@ def test_nested_cassettes_with_session_created_before_nesting(httpbin_both, tmpd
def test_post_file(tmpdir, httpbin_both):
"""Ensure that we handle posting a file."""
url = httpbin_both + "/post"
with vcr.use_cassette(str(tmpdir.join("post_file.yaml"))) as cass, open("tox.ini", "rb") as f:
with vcr.use_cassette(str(tmpdir.join("post_file.yaml"))) as cass, open(".editorconfig", "rb") as f:
original_response = requests.post(url, f).content

# This also tests that we do the right thing with matching the body when they are files.
with vcr.use_cassette(
str(tmpdir.join("post_file.yaml")),
match_on=("method", "scheme", "host", "port", "path", "query", "body"),
) as cass:
with open("tox.ini", "rb") as f:
tox_content = f.read()
assert cass.requests[0].body.read() == tox_content
with open("tox.ini", "rb") as f:
with open(".editorconfig", "rb") as f:
editorconfig = f.read()
assert cass.requests[0].body.read() == editorconfig
with open(".editorconfig", "rb") as f:
new_response = requests.post(url, f).content
assert original_response == new_response

Expand Down
74 changes: 0 additions & 74 deletions tox.ini

This file was deleted.

0 comments on commit 31a8a72

Please sign in to comment.