-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move pytest settings to pyproject and actually make use of pytest-doc…
…ker-compose for testing locally
- Loading branch information
Showing
4 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,53 @@ | ||
pytest_plugins = ['docker_compose'] | ||
import subprocess | ||
|
||
import pytest | ||
from tenacity import retry, wait_fixed, stop_after_attempt, RetryError | ||
|
||
|
||
pytest_plugins = ["docker_compose"] | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--ci", | ||
action="store_true", | ||
default=False, | ||
help="Run tests as if in a CI environment", | ||
) | ||
|
||
|
||
def wait_for_postgres_from_compose(session_scoped_container_getter): | ||
"""Wait for the postgres container to be ready.""" | ||
container = session_scoped_container_getter.get("postgres") | ||
is_ready = "accepting connections" in container.execute( | ||
["pg_isready", "-h", "localhost", "-U", "postgres"] | ||
) | ||
assert is_ready | ||
|
||
|
||
def wait_for_postgres_from_ci(): | ||
"""Wait for the postgres service to be ready.""" | ||
is_ready = ( | ||
subprocess.run(["pg_isready", "-h", "localhost", "-U", "postgres"]).returncode | ||
== 0 | ||
) | ||
assert is_ready | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
@retry(wait=wait_fixed(2), stop=stop_after_attempt(3)) | ||
def wait_for_postgres(request, session_scoped_container_getter): | ||
"""Wait for postgres to be ready. | ||
Chooses a different strategy depending on whether the tests are running with containerized postgres locally | ||
or a postgres service in a CI environment. | ||
""" | ||
if request.config.getoption("--ci"): | ||
return wait_for_postgres_from_ci() | ||
else: | ||
return wait_for_postgres_from_compose(session_scoped_container_getter) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def django_db_setup(wait_for_postgres, django_db_setup): | ||
pass |
This file was deleted.
Oops, something went wrong.