summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook@pioneer.com>2021-04-18 14:43:50 -0500
committerJordan Cook <jordan.cook@pioneer.com>2021-04-19 12:51:25 -0500
commited520b6e969c8860ad9c7488fdb6ca8100cc5862 (patch)
tree6f1a457a801e75ef4c34e09758afdc2e4868b10a
parent0423cef681e3cc76566da7a43797018f890b3057 (diff)
parentdd7ef7197a44688ed06356199f993161891363b2 (diff)
downloadrequests-cache-ed520b6e969c8860ad9c7488fdb6ca8100cc5862.tar.gz
Merge branch 'test-updates'
-rw-r--r--.github/workflows/build.yml5
-rw-r--r--CONTRIBUTING.md14
-rwxr-xr-xruntests.sh5
-rw-r--r--setup.py1
-rw-r--r--tests/conftest.py19
-rw-r--r--tests/integration/test_dynamodb.py3
6 files changed, 22 insertions, 25 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 8d3709e..4ad4fd3 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -9,6 +9,7 @@ on:
workflow_dispatch:
env:
LATEST_PY_VERSION: '3.9'
+ COVERAGE_ARGS: '--cov --cov-report=term --cov-report=html'
jobs:
# Run unit tests for each supported python version
@@ -53,8 +54,8 @@ jobs:
if: ${{ matrix.python-version == env.LATEST_PY_VERSION }}
# Run unit tests first (and with multiprocessing) to fail quickly if there are issues
run: |
- pytest tests/unit --numprocesses=auto --cov --cov-report=term --cov-report=html
- pytest tests/integration --cov --cov-report=term --cov-report=html --cov-append
+ pytest tests/unit --numprocesses=auto ${{ env.COVERAGE_ARGS }}
+ pytest tests/integration --cov-append ${{ env.COVERAGE_ARGS }}
- name: Send code coverage report to Coveralls
if: ${{ matrix.python-version == env.LATEST_PY_VERSION }}
env:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 3b734f9..6011389 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -44,8 +44,8 @@ $ pre-commit uninstall
### Test Layout
* Tests are divided into unit and integration tests:
- * Unit tests can be run without any additional setup, and don't depend on any external services
- * Integration tests depend on additional services, which are easiest to run using Docker
+ * Unit tests can be run without any additional setup, and **don't depend on any external services**.
+ * Integration tests **depend on additional services**, which are easiest to run using Docker
(see Integration Tests section below).
* See [conftest.py](https://github.com/reclosedev/requests-cache/blob/master/tests/conftest.py) for
[pytest fixtures](https://docs.pytest.org/en/stable/fixture.html) that apply the most common
@@ -83,16 +83,6 @@ pytest tests/integration/test_cache.py
For backend databases, you can install and run them on the host instead of in a container, as long
as they are running on the default port.
-## Debugging
-When you run into issues while working on new features and/or tests, it will make your life much easier
-to use a debugger instead of `print` statements. Most IDEs have a built-in debugger, but if
-you prefer the command line, [ipdb](https://github.com/gotcha/ipdb) is a good option. To install:
-```bash
-pip install ipython ipdb
-```
-
-The `runtests.sh` script will use ipdb by default, if it's installed.
-
## Documentation
[Sphinx](http://www.sphinx-doc.org/en/master/) is used to generate documentation.
diff --git a/runtests.sh b/runtests.sh
index 6b762c1..6d6d31e 100755
--- a/runtests.sh
+++ b/runtests.sh
@@ -1,8 +1,7 @@
#!/usr/bin/env bash
# Test runner script with useful pytest options
-export PYTHONBREAKPOINT='ipdb.set_trace'
COVERAGE_ARGS='--cov --cov-report=term --cov-report=html'
# Run unit tests first (and with multiprocessing) to fail quickly if there are issues
-pytest -s tests/unit --numprocesses=auto $COVERAGE_ARGS
-pytest -s tests/integration --cov-append $COVERAGE_ARGS
+pytest tests/unit --numprocesses=auto $COVERAGE_ARGS
+pytest tests/integration --cov-append $COVERAGE_ARGS
diff --git a/setup.py b/setup.py
index f942608..4d7a464 100644
--- a/setup.py
+++ b/setup.py
@@ -29,6 +29,7 @@ extras_require = {
'psutil',
'pytest>=5.0',
'pytest-cov>=2.11',
+ 'pytest-order~=0.11.0',
'pytest-xdist',
'radon',
'requests-mock>=1.8',
diff --git a/tests/conftest.py b/tests/conftest.py
index 753e345..0b3167a 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,5 +1,9 @@
"""Fixtures that will be automatically picked up by pytest
+Short description:
+* The ``mock_session`` fixture uses pre-configured mock requests, and should be used for unit tests.
+* The ``tempfile_session`` fixture makes real HTTP requests, and should be used for integration test.
+
Note: The protocol ``http(s)+mock://`` helps :py:class:`requests_mock.Adapter` play nicely with
:py:class:`requests.PreparedRequest`. More info here:
https://requests-mock.readthedocs.io/en/latest/adapter.html
@@ -37,22 +41,22 @@ def httpbin(path):
return f'{base_url}/{path}'
-"""The following allows pytest-httpbin to be used instead of the httpbin container.
-A server will be started via an autoused fixture if both:
-* pytest-httpbin is installed
-* The environment variable USE_PYTEST_HTTPBIN is set to 'true'
-"""
try:
import pytest_httpbin # noqa: F401
USE_PYTEST_HTTPBIN = os.getenv('USE_PYTEST_HTTPBIN', '').lower() == 'true'
- logger.info('Using pytest-httpin for integration tests')
except ImportError:
USE_PYTEST_HTTPBIN = False
@pytest.fixture(scope='session', autouse=USE_PYTEST_HTTPBIN)
def httpbin_wrapper(httpbin):
+ """Allow pytest-httpbin to be used instead of the httpbin Docker container. This fixture does
+ not need to be used manually. It will be autoused if both:
+ * pytest-httpbin is installed
+ * The environment variable USE_PYTEST_HTTPBIN is set to 'true'
+ """
+ logger.info('Using pytest-httpin for integration tests')
os.environ['HTTPBIN_URL'] = httpbin.url
return httpbin
@@ -95,7 +99,6 @@ def tempfile_session() -> CachedSession:
suppress_warnings=True,
)
yield session
- requests_cache.uninstall_cache()
@pytest.fixture(scope='function')
@@ -167,7 +170,7 @@ def fail_if_no_connection(func) -> bool:
@wraps(func)
def wrapper(*args, **kwargs):
try:
- timeout(0.5)(func)(*args, **kwargs)
+ timeout(1.0)(func)(*args, **kwargs)
except Exception as e:
logger.error(e)
pytest.fail('Could not connect to backend')
diff --git a/tests/integration/test_dynamodb.py b/tests/integration/test_dynamodb.py
index 2f4e7fb..a79118b 100644
--- a/tests/integration/test_dynamodb.py
+++ b/tests/integration/test_dynamodb.py
@@ -5,6 +5,9 @@ from requests_cache.backends import DynamoDbDict
from tests.conftest import fail_if_no_connection
from tests.integration.test_backends import BaseStorageTestCase
+# Run this test module last, since the DynamoDB container takes the longest to initialize
+pytestmark = pytest.mark.order(-1)
+
boto_options = {
'endpoint_url': 'http://localhost:8000',
'region_name': 'us-east-1',