From 7abbad17b8504215f230cf8646b82fa775bf4e4e Mon Sep 17 00:00:00 2001 From: Jair Henrique Date: Sun, 10 Dec 2023 21:17:15 -0300 Subject: [PATCH] Run tests without tox --- .github/workflows/main.yml | 32 +++++++------ MANIFEST.in | 1 - docs/contributing.rst | 43 ++++------------- setup.py | 48 ++++++++++--------- tests/integration/test_requests.py | 10 ++-- tox.ini | 74 ------------------------------ 6 files changed, 61 insertions(+), 147 deletions(-) delete mode 100644 tox.ini diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 53f148879..264081cc8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,18 @@ 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" + - "urllib3<2" steps: - uses: actions/checkout@v4 @@ -22,22 +33,17 @@ 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 + set -xe + pip install --upgrade pip + pip install codecov .[tests] '${{ matrix.urllib3-requirement }}' + pip check - - 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 diff --git a/MANIFEST.in b/MANIFEST.in index 9fc7449c5..2606d1274 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,5 @@ include README.rst include LICENSE.txt -include tox.ini recursive-include tests * recursive-exclude * __pycache__ recursive-exclude * *.py[co] diff --git a/docs/contributing.rst b/docs/contributing.rst index 6cbc41d90..571623862 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -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 `__, but you can also run them -yourself using `pytest `__ and -`Tox `__. +The tests are all run automatically on `Github Actions CI `__, +but you can also run them yourself using `pytest `__. -Tox will automatically run them in all environments VCR.py supports if they are available on your `PATH`. Alternatively you can use `tox-pyenv `_ with -`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} -- - - 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 `__ 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 `_ -but we are also going to use `tox-pyenv `_ in this example:: git clone https://github.com/pyenv/pyenv ~/.pyenv @@ -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 diff --git a/setup.py b/setup.py index 71ba6a249..b12915ea0 100644 --- a/setup.py +++ b/setup.py @@ -52,29 +52,34 @@ def run_tests(self): # so this block and the dependency can be dropped at some point # in the future. For more Details: # https://github.com/kevin1024/vcrpy/pull/699#issuecomment-1551439663 - "urllib3 <2; python_version <'3.10'", + # "urllib3 <2; python_version <'3.10'", # https://github.com/kevin1024/vcrpy/pull/775#issuecomment-1847849962 - "urllib3 <2; platform_python_implementation =='PyPy'", + # "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", -] +extras_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", @@ -89,7 +94,8 @@ def run_tests(self): python_requires=">=3.8", install_requires=install_requires, license="MIT", - tests_require=tests_require, + extras_require=extras_require, + tests_require=extras_require["tests"], classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Console", diff --git a/tests/integration/test_requests.py b/tests/integration/test_requests.py index 48590fc22..10cbd2115 100644 --- a/tests/integration/test_requests.py +++ b/tests/integration/test_requests.py @@ -265,7 +265,7 @@ 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. @@ -273,10 +273,10 @@ def test_post_file(tmpdir, httpbin_both): 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 diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 299231548..000000000 --- a/tox.ini +++ /dev/null @@ -1,74 +0,0 @@ -[tox] -skip_missing_interpreters=true -envlist = - cov-clean, - {py38,py39,py310,py311,py312}-{requests-urllib3-1,httplib2,urllib3-1,tornado4,boto3,aiohttp,httpx}, - {py310,py311,py312}-{requests-urllib3-2,urllib3-2}, - {pypy3}-{requests-urllib3-1,httplib2,urllib3-1,tornado4,boto3}, - #{py310}-httpx019, - cov-report - - -[gh-actions] -python = - 3.8: py38 - 3.9: py39 - 3.10: py310 - 3.11: py311 - 3.12: py312 - pypy-3: pypy3 - -# Coverage environment tasks: cov-clean and cov-report -# https://pytest-cov.readthedocs.io/en/latest/tox.html -[testenv:cov-clean] -deps = coverage -skip_install=true -commands = coverage erase - -[testenv:cov-report] -deps = coverage -skip_install=true -commands = - coverage html - coverage report --fail-under=90 - -[testenv] -# Need to use develop install so that paths -# for aggregate code coverage combine -usedevelop=true -commands = - ./runtests.sh --cov=./vcr --cov-branch --cov-report=xml --cov-append {posargs} -allowlist_externals = - ./runtests.sh -deps = - Werkzeug==2.0.3 - pytest - pytest-httpbin>=1.0.1 - pytest-cov - PyYAML - ipaddress - requests: requests>=2.22.0 - httplib2: httplib2 - urllib3-1: urllib3<2 - urllib3-2: urllib3<3 - boto3: boto3 - aiohttp: aiohttp - aiohttp: pytest-asyncio - aiohttp: pytest-aiohttp - httpx: httpx - {py38,py39,py310}-{httpx}: httpx - {py38,py39,py310}-{httpx}: pytest-asyncio - httpx: httpx>0.19 - httpx019: httpx==0.19 - {py38,py39,py310}-{httpx}: pytest-asyncio -depends = - {py38,py39,py310,py311,py312,pypy3}-{requests-urllib3-1,httplib2,urllib3-1,tornado4,boto3},{py310,py311,py312}-{requests-urllib3-2,urllib3-2},{py38,py39,py310,py311,py312}-{aiohttp},{py38,py39,py310,py311,py312}-{httpx}: cov-clean - cov-report: {py38,py39,py310,py311,py312,pypy3}-{requests-urllib3-1,httplib2,urllib3-1,tornado4,boto3},{py310,py311,py312}-{requests-urllib3-2,urllib3-2},{py38,py39,py310,py311,py312}-{aiohttp} -passenv = - AWS_ACCESS_KEY_ID - AWS_DEFAULT_REGION - AWS_SECRET_ACCESS_KEY -setenv = - # workaround for broken C extension in aiohttp - # see: https://github.com/aio-libs/aiohttp/issues/7229 - py312: AIOHTTP_NO_EXTENSIONS=1