diff options
-rw-r--r-- | CONTRIBUTING.md | 4 | ||||
-rw-r--r-- | tests/conftest.py | 16 |
2 files changed, 12 insertions, 8 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3b734f9..14d71c8 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 diff --git a/tests/conftest.py b/tests/conftest.py index 753e345..17dfbc7 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 |