pytest-databases 0.4.1__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/PKG-INFO +1 -1
  2. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/pyproject.toml +1 -1
  3. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/__init__.py +0 -22
  4. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/alloydb_omni.py +46 -14
  5. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/bigquery.py +52 -20
  6. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/cockroachdb.py +44 -12
  7. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/dragonfly.py +41 -10
  8. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/elastic_search.py +62 -27
  9. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/keydb.py +42 -10
  10. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/mariadb.py +55 -22
  11. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/mssql.py +57 -24
  12. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/mysql.py +71 -36
  13. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/oracle.py +65 -31
  14. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/postgres.py +87 -50
  15. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/redis.py +42 -10
  16. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/spanner.py +48 -16
  17. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/conftest.py +1 -1
  18. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/test_alloydb_omni.py +2 -2
  19. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/test_bigquery.py +4 -4
  20. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/test_cockroachdb.py +4 -2
  21. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/test_dragonfly.py +2 -2
  22. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/test_elasticsearch.py +14 -14
  23. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/test_keydb.py +2 -2
  24. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/test_mariadb.py +4 -4
  25. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/test_mssql.py +6 -6
  26. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/test_mysql.py +8 -8
  27. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/test_oracle.py +8 -4
  28. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/test_postgres.py +12 -12
  29. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/test_redis.py +2 -2
  30. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/test_spanner.py +2 -2
  31. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/.gitignore +0 -0
  32. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/.pre-commit-config.yaml +0 -0
  33. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/.sourcery.yaml +0 -0
  34. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/.vscode/launch.json +0 -0
  35. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/.vscode/settings.json +0 -0
  36. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/CODEOWNERS +0 -0
  37. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/CONTRIBUTING.rst +0 -0
  38. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/LICENSE +0 -0
  39. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/Makefile +0 -0
  40. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/README.md +0 -0
  41. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/requirements/requirements-dev.txt +0 -0
  42. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/requirements/requirements-docs.txt +0 -0
  43. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/requirements/requirements.txt +0 -0
  44. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/scripts/__init__.py +0 -0
  45. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/scripts/build_docs.py +0 -0
  46. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/scripts/convert_docs.sh +0 -0
  47. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/sonar-project.properties +0 -0
  48. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/__init__.py +0 -0
  49. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/__metadata__.py +0 -0
  50. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/docker-compose.alloydb-omni.yml +0 -0
  51. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/docker-compose.bigquery.yml +0 -0
  52. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/docker-compose.cockroachdb.yml +0 -0
  53. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/docker-compose.dragonfly.yml +0 -0
  54. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/docker-compose.elasticsearch.yml +0 -0
  55. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/docker-compose.keydb.yml +0 -0
  56. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/docker-compose.mariadb.yml +0 -0
  57. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/docker-compose.mssql.yml +0 -0
  58. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/docker-compose.mysql.yml +0 -0
  59. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/docker-compose.oracle.yml +0 -0
  60. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/docker-compose.postgres.yml +0 -0
  61. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/docker-compose.redis.yml +0 -0
  62. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/docker/docker-compose.spanner.yml +0 -0
  63. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/helpers.py +0 -0
  64. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/src/pytest_databases/py.typed +0 -0
  65. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/__init__.py +0 -0
  66. {pytest_databases-0.4.1 → pytest_databases-0.5.0}/tests/docker/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pytest-databases
3
- Version: 0.4.1
3
+ Version: 0.5.0
4
4
  Summary: Reusable database fixtures for any and all databases.
5
5
  Project-URL: Documentation, https://github.com/litestar-org/pytest-databases#readme
6
6
  Project-URL: Issues, https://github.com/litestar-org/pytest-databases/issues
@@ -12,7 +12,7 @@ license = "MIT"
12
12
  name = "pytest-databases"
13
13
  readme = "README.md"
14
14
  requires-python = ">=3.8"
15
- version = "0.4.1"
15
+ version = "0.5.0"
16
16
  #
17
17
  authors = [{ name = "Cody Fincher", email = "cody.fincher@gmail.com" }]
18
18
  keywords = [
@@ -130,25 +130,3 @@ class DockerServiceRegistry:
130
130
  def down(self) -> None:
131
131
  if not SKIP_DOCKER_COMPOSE:
132
132
  self.run_command("down", "-t", "10")
133
-
134
-
135
- @pytest.fixture(scope="session")
136
- def compose_project_name() -> str:
137
- return os.environ.get("COMPOSE_PROJECT_NAME", COMPOSE_PROJECT_NAME)
138
-
139
-
140
- @pytest.fixture(scope="session")
141
- def docker_services(compose_project_name: str, worker_id: str = "main") -> Generator[DockerServiceRegistry, None, None]:
142
- if os.getenv("GITHUB_ACTIONS") == "true" and sys.platform != "linux":
143
- pytest.skip("Docker not available on this platform")
144
-
145
- registry = DockerServiceRegistry(worker_id, compose_project_name=compose_project_name)
146
- try:
147
- yield registry
148
- finally:
149
- registry.down()
150
-
151
-
152
- @pytest.fixture(scope="session")
153
- def docker_ip(docker_services: DockerServiceRegistry) -> str:
154
- return docker_services.docker_ip
@@ -24,14 +24,21 @@
24
24
  from __future__ import annotations
25
25
 
26
26
  import os
27
+ import sys
27
28
  from pathlib import Path
28
- from typing import TYPE_CHECKING
29
+ from typing import TYPE_CHECKING, AsyncGenerator
29
30
 
30
31
  import asyncpg
31
32
  import pytest
32
33
 
34
+ from pytest_databases.docker import DockerServiceRegistry
35
+ from pytest_databases.helpers import simple_string_hash
36
+
33
37
  if TYPE_CHECKING:
34
- from pytest_databases.docker import DockerServiceRegistry
38
+ from collections.abc import Generator
39
+
40
+
41
+ COMPOSE_PROJECT_NAME: str = f"pytest-databases-alloydb-{simple_string_hash(__file__)}"
35
42
 
36
43
 
37
44
  async def alloydb_omni_responsive(host: str, port: int, user: str, password: str, database: str) -> bool:
@@ -53,54 +60,78 @@ async def alloydb_omni_responsive(host: str, port: int, user: str, password: str
53
60
  await conn.close()
54
61
 
55
62
 
56
- @pytest.fixture()
63
+ @pytest.fixture(scope="session")
64
+ def alloydb_compose_project_name() -> str:
65
+ return os.environ.get("COMPOSE_PROJECT_NAME", COMPOSE_PROJECT_NAME)
66
+
67
+
68
+ @pytest.fixture(autouse=False, scope="session")
69
+ def alloydb_docker_services(
70
+ alloydb_compose_project_name: str, worker_id: str = "main"
71
+ ) -> Generator[DockerServiceRegistry, None, None]:
72
+ if os.getenv("GITHUB_ACTIONS") == "true" and sys.platform != "linux":
73
+ pytest.skip("Docker not available on this platform")
74
+
75
+ registry = DockerServiceRegistry(worker_id, compose_project_name=alloydb_compose_project_name)
76
+ try:
77
+ yield registry
78
+ finally:
79
+ registry.down()
80
+
81
+
82
+ @pytest.fixture(scope="session")
57
83
  def postgres_user() -> str:
58
84
  return "postgres"
59
85
 
60
86
 
61
- @pytest.fixture()
87
+ @pytest.fixture(scope="session")
62
88
  def postgres_password() -> str:
63
89
  return "super-secret"
64
90
 
65
91
 
66
- @pytest.fixture()
92
+ @pytest.fixture(scope="session")
67
93
  def postgres_database() -> str:
68
94
  return "postgres"
69
95
 
70
96
 
71
- @pytest.fixture()
97
+ @pytest.fixture(scope="session")
72
98
  def alloydb_omni_port() -> int:
73
99
  return 5420
74
100
 
75
101
 
76
- @pytest.fixture()
102
+ @pytest.fixture(scope="session")
77
103
  def default_alloydb_omni_service_name() -> str:
78
104
  return "alloydb"
79
105
 
80
106
 
81
107
  @pytest.fixture(scope="session")
82
- def docker_compose_files() -> list[Path]:
108
+ def alloydb_docker_compose_files() -> list[Path]:
83
109
  return [Path(Path(__file__).parent / "docker-compose.alloydb-omni.yml")]
84
110
 
85
111
 
112
+ @pytest.fixture(scope="session")
113
+ def alloydb_docker_ip(alloydb_docker_services: DockerServiceRegistry) -> str:
114
+ return alloydb_docker_services.docker_ip
115
+
116
+
86
117
  # alias to the latest
87
- @pytest.fixture(autouse=False)
118
+ @pytest.fixture(autouse=False, scope="session")
88
119
  async def alloydb_omni_service(
89
- docker_services: DockerServiceRegistry,
120
+ alloydb_docker_services: DockerServiceRegistry,
90
121
  default_alloydb_omni_service_name: str,
91
- docker_compose_files: list[Path],
122
+ alloydb_docker_compose_files: list[Path],
92
123
  alloydb_omni_port: int,
93
124
  postgres_database: str,
94
125
  postgres_user: str,
95
126
  postgres_password: str,
96
- ) -> None:
127
+ ) -> AsyncGenerator[None, None]:
97
128
  os.environ["POSTGRES_PASSWORD"] = postgres_password
98
129
  os.environ["POSTGRES_USER"] = postgres_user
99
130
  os.environ["POSTGRES_DATABASE"] = postgres_database
100
131
  os.environ[f"{default_alloydb_omni_service_name.upper()}_PORT"] = str(alloydb_omni_port)
101
- await docker_services.start(
132
+ await alloydb_docker_services.start(
102
133
  name=default_alloydb_omni_service_name,
103
- docker_compose_files=docker_compose_files,
134
+ docker_compose_files=alloydb_docker_compose_files,
104
135
  timeout=45,
105
136
  pause=1,
106
137
  check=alloydb_omni_responsive,
@@ -109,3 +140,4 @@ async def alloydb_omni_service(
109
140
  user=postgres_user,
110
141
  password=postgres_password,
111
142
  )
143
+ yield
@@ -24,16 +24,23 @@
24
24
  from __future__ import annotations
25
25
 
26
26
  import os
27
+ import sys
27
28
  from pathlib import Path
28
- from typing import TYPE_CHECKING
29
+ from typing import TYPE_CHECKING, AsyncGenerator
29
30
 
30
31
  import pytest
31
32
  from google.api_core.client_options import ClientOptions
32
33
  from google.auth.credentials import AnonymousCredentials, Credentials
33
34
  from google.cloud import bigquery
34
35
 
36
+ from pytest_databases.docker import DockerServiceRegistry
37
+ from pytest_databases.helpers import simple_string_hash
38
+
35
39
  if TYPE_CHECKING:
36
- from pytest_databases.docker import DockerServiceRegistry
40
+ from collections.abc import Generator
41
+
42
+
43
+ COMPOSE_PROJECT_NAME: str = f"pytest-databases-bigquery-{simple_string_hash(__file__)}"
37
44
 
38
45
 
39
46
  async def bigquery_responsive(
@@ -57,43 +64,57 @@ async def bigquery_responsive(
57
64
  return False
58
65
 
59
66
 
60
- @pytest.fixture
67
+ @pytest.fixture(scope="session")
68
+ def bigquery_compose_project_name() -> str:
69
+ return os.environ.get("COMPOSE_PROJECT_NAME", COMPOSE_PROJECT_NAME)
70
+
71
+
72
+ @pytest.fixture(autouse=False, scope="session")
73
+ def bigquery_docker_services(
74
+ bigquery_compose_project_name: str, worker_id: str = "main"
75
+ ) -> Generator[DockerServiceRegistry, None, None]:
76
+ if os.getenv("GITHUB_ACTIONS") == "true" and sys.platform != "linux":
77
+ pytest.skip("Docker not available on this platform")
78
+
79
+ registry = DockerServiceRegistry(worker_id, compose_project_name=bigquery_compose_project_name)
80
+ try:
81
+ yield registry
82
+ finally:
83
+ registry.down()
84
+
85
+
86
+ @pytest.fixture(scope="session")
61
87
  def bigquery_port() -> int:
62
88
  return 9051
63
89
 
64
90
 
65
- @pytest.fixture
91
+ @pytest.fixture(scope="session")
66
92
  def bigquery_grpc_port() -> int:
67
93
  return 9061
68
94
 
69
95
 
70
- @pytest.fixture
71
- def bigquery_endpoint(docker_ip: str, bigquery_port: int) -> str:
72
- return f"http://{docker_ip}:{bigquery_port}"
73
-
74
-
75
- @pytest.fixture
96
+ @pytest.fixture(scope="session")
76
97
  def bigquery_dataset() -> str:
77
98
  return "test-dataset"
78
99
 
79
100
 
80
- @pytest.fixture
101
+ @pytest.fixture(scope="session")
81
102
  def bigquery_project() -> str:
82
103
  return "emulator-test-project"
83
104
 
84
105
 
85
- @pytest.fixture()
106
+ @pytest.fixture(scope="session")
86
107
  def bigquery_client_options(bigquery_endpoint: str) -> ClientOptions:
87
108
  return ClientOptions(api_endpoint=bigquery_endpoint)
88
109
 
89
110
 
90
- @pytest.fixture
111
+ @pytest.fixture(scope="session")
91
112
  def bigquery_credentials() -> Credentials:
92
113
  return AnonymousCredentials()
93
114
 
94
115
 
95
116
  @pytest.fixture(scope="session")
96
- def docker_compose_files() -> list[Path]:
117
+ def bigquery_docker_compose_files() -> list[Path]:
97
118
  return [Path(Path(__file__).parent / "docker-compose.bigquery.yml")]
98
119
 
99
120
 
@@ -102,11 +123,21 @@ def default_bigquery_service_name() -> str:
102
123
  return "bigquery"
103
124
 
104
125
 
105
- @pytest.fixture(autouse=False)
126
+ @pytest.fixture(scope="session")
127
+ def bigquery_docker_ip(bigquery_docker_services: DockerServiceRegistry) -> str:
128
+ return bigquery_docker_services.docker_ip
129
+
130
+
131
+ @pytest.fixture(scope="session")
132
+ def bigquery_endpoint(bigquery_docker_ip: str, bigquery_port: int) -> str:
133
+ return f"http://{bigquery_docker_ip}:{bigquery_port}"
134
+
135
+
136
+ @pytest.fixture(autouse=False, scope="session")
106
137
  async def bigquery_service(
107
- docker_services: DockerServiceRegistry,
138
+ bigquery_docker_services: DockerServiceRegistry,
108
139
  default_bigquery_service_name: str,
109
- docker_compose_files: list[Path],
140
+ bigquery_docker_compose_files: list[Path],
110
141
  bigquery_port: int,
111
142
  bigquery_grpc_port: int,
112
143
  bigquery_endpoint: str,
@@ -114,15 +145,15 @@ async def bigquery_service(
114
145
  bigquery_project: str,
115
146
  bigquery_credentials: Credentials,
116
147
  bigquery_client_options: ClientOptions,
117
- ) -> None:
148
+ ) -> AsyncGenerator[None, None]:
118
149
  os.environ["BIGQUERY_ENDPOINT"] = bigquery_endpoint
119
150
  os.environ["BIGQUERY_DATASET"] = bigquery_dataset
120
151
  os.environ["BIGQUERY_PORT"] = str(bigquery_port)
121
152
  os.environ["BIGQUERY_GRPC_PORT"] = str(bigquery_grpc_port)
122
153
  os.environ["GOOGLE_CLOUD_PROJECT"] = bigquery_project
123
- await docker_services.start(
154
+ await bigquery_docker_services.start(
124
155
  name=default_bigquery_service_name,
125
- docker_compose_files=docker_compose_files,
156
+ docker_compose_files=bigquery_docker_compose_files,
126
157
  timeout=60,
127
158
  check=bigquery_responsive,
128
159
  bigquery_endpoint=bigquery_endpoint,
@@ -131,3 +162,4 @@ async def bigquery_service(
131
162
  bigquery_credentials=bigquery_credentials,
132
163
  bigquery_client_options=bigquery_client_options,
133
164
  )
165
+ yield
@@ -23,14 +23,21 @@
23
23
  from __future__ import annotations
24
24
 
25
25
  import os
26
+ import sys
26
27
  from pathlib import Path
27
- from typing import TYPE_CHECKING
28
+ from typing import TYPE_CHECKING, AsyncGenerator
28
29
 
29
30
  import psycopg
30
31
  import pytest
31
32
 
33
+ from pytest_databases.docker import DockerServiceRegistry
34
+ from pytest_databases.helpers import simple_string_hash
35
+
32
36
  if TYPE_CHECKING:
33
- from pytest_databases.docker import DockerServiceRegistry
37
+ from collections.abc import Generator
38
+
39
+
40
+ COMPOSE_PROJECT_NAME: str = f"pytest-databases-cockroachdb-{simple_string_hash(__file__)}"
34
41
 
35
42
 
36
43
  async def cockroachdb_responsive(host: str, port: int, database: str, driver_opts: dict[str, str]) -> bool:
@@ -44,23 +51,42 @@ async def cockroachdb_responsive(host: str, port: int, database: str, driver_opt
44
51
  return False
45
52
 
46
53
 
47
- @pytest.fixture()
54
+ @pytest.fixture(scope="session")
55
+ def cockroachdb_compose_project_name() -> str:
56
+ return os.environ.get("COMPOSE_PROJECT_NAME", COMPOSE_PROJECT_NAME)
57
+
58
+
59
+ @pytest.fixture(autouse=False, scope="session")
60
+ def cockroachdb_docker_services(
61
+ cockroachdb_compose_project_name: str, worker_id: str = "main"
62
+ ) -> Generator[DockerServiceRegistry, None, None]:
63
+ if os.getenv("GITHUB_ACTIONS") == "true" and sys.platform != "linux":
64
+ pytest.skip("Docker not available on this platform")
65
+
66
+ registry = DockerServiceRegistry(worker_id, compose_project_name=cockroachdb_compose_project_name)
67
+ try:
68
+ yield registry
69
+ finally:
70
+ registry.down()
71
+
72
+
73
+ @pytest.fixture(scope="session")
48
74
  def cockroachdb_port() -> int:
49
75
  return 26257
50
76
 
51
77
 
52
- @pytest.fixture()
78
+ @pytest.fixture(scope="session")
53
79
  def cockroachdb_database() -> str:
54
80
  return "defaultdb"
55
81
 
56
82
 
57
- @pytest.fixture()
83
+ @pytest.fixture(scope="session")
58
84
  def cockroachdb_driver_opts() -> dict[str, str]:
59
85
  return {"sslmode": "disable"}
60
86
 
61
87
 
62
88
  @pytest.fixture(scope="session")
63
- def docker_compose_files() -> list[Path]:
89
+ def cockroachdb_docker_compose_files() -> list[Path]:
64
90
  return [Path(Path(__file__).parent / "docker-compose.cockroachdb.yml")]
65
91
 
66
92
 
@@ -69,20 +95,25 @@ def default_cockroachdb_service_name() -> str:
69
95
  return "cockroachdb"
70
96
 
71
97
 
72
- @pytest.fixture(autouse=False)
98
+ @pytest.fixture(scope="session")
99
+ def cockroachdb_docker_ip(cockroachdb_docker_services: DockerServiceRegistry) -> str:
100
+ return cockroachdb_docker_services.docker_ip
101
+
102
+
103
+ @pytest.fixture(autouse=False, scope="session")
73
104
  async def cockroachdb_service(
74
- docker_services: DockerServiceRegistry,
105
+ cockroachdb_docker_services: DockerServiceRegistry,
75
106
  default_cockroachdb_service_name: str,
76
- docker_compose_files: list[Path],
107
+ cockroachdb_docker_compose_files: list[Path],
77
108
  cockroachdb_port: int,
78
109
  cockroachdb_database: str,
79
110
  cockroachdb_driver_opts: dict[str, str],
80
- ) -> None:
111
+ ) -> AsyncGenerator[None, None]:
81
112
  os.environ["COCKROACHDB_DATABASE"] = cockroachdb_database
82
113
  os.environ["COCKROACHDB_PORT"] = str(cockroachdb_port)
83
- await docker_services.start(
114
+ await cockroachdb_docker_services.start(
84
115
  name=default_cockroachdb_service_name,
85
- docker_compose_files=docker_compose_files,
116
+ docker_compose_files=cockroachdb_docker_compose_files,
86
117
  timeout=60,
87
118
  pause=1,
88
119
  check=cockroachdb_responsive,
@@ -90,3 +121,4 @@ async def cockroachdb_service(
90
121
  database=cockroachdb_database,
91
122
  driver_opts=cockroachdb_driver_opts,
92
123
  )
124
+ yield
@@ -24,15 +24,21 @@
24
24
  from __future__ import annotations
25
25
 
26
26
  import os
27
+ import sys
27
28
  from pathlib import Path
28
- from typing import TYPE_CHECKING
29
+ from typing import TYPE_CHECKING, AsyncGenerator
29
30
 
30
31
  import pytest
31
32
  from redis.asyncio import Redis as AsyncRedis
32
33
  from redis.exceptions import ConnectionError as RedisConnectionError
33
34
 
35
+ from pytest_databases.docker import DockerServiceRegistry
36
+ from pytest_databases.helpers import simple_string_hash
37
+
34
38
  if TYPE_CHECKING:
35
- from pytest_databases.docker import DockerServiceRegistry
39
+ from collections.abc import Generator
40
+
41
+ COMPOSE_PROJECT_NAME: str = f"pytest-databases-dragonfly-{simple_string_hash(__file__)}"
36
42
 
37
43
 
38
44
  async def dragonfly_responsive(host: str, port: int) -> bool:
@@ -45,13 +51,32 @@ async def dragonfly_responsive(host: str, port: int) -> bool:
45
51
  await client.aclose() # type: ignore[attr-defined]
46
52
 
47
53
 
48
- @pytest.fixture()
54
+ @pytest.fixture(scope="session")
55
+ def dragonfly_compose_project_name() -> str:
56
+ return os.environ.get("COMPOSE_PROJECT_NAME", COMPOSE_PROJECT_NAME)
57
+
58
+
59
+ @pytest.fixture(autouse=False, scope="session")
60
+ def dragonfly_docker_services(
61
+ dragonfly_compose_project_name: str, worker_id: str = "main"
62
+ ) -> Generator[DockerServiceRegistry, None, None]:
63
+ if os.getenv("GITHUB_ACTIONS") == "true" and sys.platform != "linux":
64
+ pytest.skip("Docker not available on this platform")
65
+
66
+ registry = DockerServiceRegistry(worker_id, compose_project_name=dragonfly_compose_project_name)
67
+ try:
68
+ yield registry
69
+ finally:
70
+ registry.down()
71
+
72
+
73
+ @pytest.fixture(scope="session")
49
74
  def dragonfly_port() -> int:
50
75
  return 6398
51
76
 
52
77
 
53
78
  @pytest.fixture(scope="session")
54
- def docker_compose_files() -> list[Path]:
79
+ def dragonfly_docker_compose_files() -> list[Path]:
55
80
  return [Path(Path(__file__).parent / "docker-compose.dragonfly.yml")]
56
81
 
57
82
 
@@ -60,17 +85,23 @@ def default_dragonfly_service_name() -> str:
60
85
  return "dragonfly"
61
86
 
62
87
 
63
- @pytest.fixture(autouse=False)
88
+ @pytest.fixture(scope="session")
89
+ def dragonfly_docker_ip(dragonfly_docker_services: DockerServiceRegistry) -> str:
90
+ return dragonfly_docker_services.docker_ip
91
+
92
+
93
+ @pytest.fixture(autouse=False, scope="session")
64
94
  async def dragonfly_service(
65
- docker_services: DockerServiceRegistry,
95
+ dragonfly_docker_services: DockerServiceRegistry,
66
96
  default_dragonfly_service_name: str,
67
- docker_compose_files: list[Path],
97
+ dragonfly_docker_compose_files: list[Path],
68
98
  dragonfly_port: int,
69
- ) -> None:
99
+ ) -> AsyncGenerator[None, None]:
70
100
  os.environ["DRAGONFLY_PORT"] = str(dragonfly_port)
71
- await docker_services.start(
101
+ await dragonfly_docker_services.start(
72
102
  name=default_dragonfly_service_name,
73
- docker_compose_files=docker_compose_files,
103
+ docker_compose_files=dragonfly_docker_compose_files,
74
104
  check=dragonfly_responsive,
75
105
  port=dragonfly_port,
76
106
  )
107
+ yield
@@ -23,15 +23,23 @@
23
23
 
24
24
  from __future__ import annotations
25
25
 
26
+ import os
27
+ import sys
26
28
  from pathlib import Path
27
- from typing import TYPE_CHECKING
29
+ from typing import TYPE_CHECKING, AsyncGenerator
28
30
 
29
31
  import pytest
30
32
  from elasticsearch7 import AsyncElasticsearch as Elasticsearch7
31
33
  from elasticsearch7 import AsyncElasticsearch as Elasticsearch8
32
34
 
35
+ from pytest_databases.docker import DockerServiceRegistry
36
+ from pytest_databases.helpers import simple_string_hash
37
+
33
38
  if TYPE_CHECKING:
34
- from pytest_databases.docker import DockerServiceRegistry
39
+ from collections.abc import Generator
40
+
41
+
42
+ COMPOSE_PROJECT_NAME: str = f"pytest-databases-elasticsearch-{simple_string_hash(__file__)}"
35
43
 
36
44
 
37
45
  async def elasticsearch7_responsive(scheme: str, host: str, port: int, user: str, password: str, database: str) -> bool:
@@ -54,38 +62,57 @@ async def elasticsearch8_responsive(scheme: str, host: str, port: int, user: str
54
62
  return False
55
63
 
56
64
 
57
- @pytest.fixture
65
+ @pytest.fixture(scope="session")
66
+ def elasticsearch_compose_project_name() -> str:
67
+ return os.environ.get("COMPOSE_PROJECT_NAME", COMPOSE_PROJECT_NAME)
68
+
69
+
70
+ @pytest.fixture(autouse=False, scope="session")
71
+ def elasticsearch_docker_services(
72
+ elasticsearch_compose_project_name: str, worker_id: str = "main"
73
+ ) -> Generator[DockerServiceRegistry, None, None]:
74
+ if os.getenv("GITHUB_ACTIONS") == "true" and sys.platform != "linux":
75
+ pytest.skip("Docker not available on this platform")
76
+
77
+ registry = DockerServiceRegistry(worker_id, compose_project_name=elasticsearch_compose_project_name)
78
+ try:
79
+ yield registry
80
+ finally:
81
+ registry.down()
82
+
83
+
84
+ @pytest.fixture(scope="session")
58
85
  def elasticsearch_user() -> str:
59
86
  return "elastic"
60
87
 
61
88
 
62
- @pytest.fixture
89
+ @pytest.fixture(scope="session")
63
90
  def elasticsearch_password() -> str:
64
91
  return "changeme"
65
92
 
66
93
 
67
- @pytest.fixture
94
+ @pytest.fixture(scope="session")
68
95
  def elasticsearch_database() -> str:
69
96
  return "db"
70
97
 
71
98
 
72
- @pytest.fixture
99
+ @pytest.fixture(scope="session")
73
100
  def elasticsearch_scheme() -> str:
74
101
  return "http"
75
102
 
76
103
 
77
- @pytest.fixture
104
+ @pytest.fixture(scope="session")
78
105
  def elasticsearch7_port() -> int:
79
106
  return 9200
80
107
 
81
108
 
82
- @pytest.fixture
109
+ @pytest.fixture(scope="session")
83
110
  def elasticsearch8_port() -> int:
84
111
  return 9201
85
112
 
86
113
 
87
114
  @pytest.fixture(scope="session")
88
- def docker_compose_files() -> list[Path]:
115
+ def elasticsearch_docker_compose_files() -> list[Path]:
89
116
  return [Path(Path(__file__).parent / "docker-compose.elasticsearch.yml")]
90
117
 
91
118
 
@@ -94,19 +121,24 @@ def default_elasticsearch_service_name() -> str:
94
121
  return "elasticsearch8"
95
122
 
96
123
 
97
- @pytest.fixture(autouse=False)
124
+ @pytest.fixture(scope="session")
125
+ def elasticsearch_docker_ip(elasticsearch_docker_services: DockerServiceRegistry) -> str:
126
+ return elasticsearch_docker_services.docker_ip
127
+
128
+
129
+ @pytest.fixture(autouse=False, scope="session")
98
130
  async def elasticsearch7_service(
99
- docker_services: DockerServiceRegistry,
100
- docker_compose_files: list[Path],
131
+ elasticsearch_docker_services: DockerServiceRegistry,
132
+ elasticsearch_docker_compose_files: list[Path],
101
133
  elasticsearch7_port: int,
102
134
  elasticsearch_database: str,
103
135
  elasticsearch_user: str,
104
136
  elasticsearch_password: str,
105
137
  elasticsearch_scheme: str,
106
- ) -> None:
107
- await docker_services.start(
138
+ ) -> AsyncGenerator[None, None]:
139
+ await elasticsearch_docker_services.start(
108
140
  "elasticsearch7",
109
- docker_compose_files=docker_compose_files,
141
+ docker_compose_files=elasticsearch_docker_compose_files,
110
142
  timeout=45,
111
143
  pause=1,
112
144
  check=elasticsearch7_responsive,
@@ -116,21 +148,22 @@ async def elasticsearch7_service(
116
148
  password=elasticsearch_password,
117
149
  scheme=elasticsearch_scheme,
118
150
  )
151
+ yield
119
152
 
120
153
 
121
- @pytest.fixture(autouse=False)
154
+ @pytest.fixture(autouse=False, scope="session")
122
155
  async def elasticsearch8_service(
123
- docker_services: DockerServiceRegistry,
124
- docker_compose_files: list[Path],
156
+ elasticsearch_docker_services: DockerServiceRegistry,
157
+ elasticsearch_docker_compose_files: list[Path],
125
158
  elasticsearch8_port: int,
126
159
  elasticsearch_database: str,
127
160
  elasticsearch_user: str,
128
161
  elasticsearch_password: str,
129
162
  elasticsearch_scheme: str,
130
- ) -> None:
131
- await docker_services.start(
163
+ ) -> AsyncGenerator[None, None]:
164
+ await elasticsearch_docker_services.start(
132
165
  "elasticsearch8",
133
- docker_compose_files=docker_compose_files,
166
+ docker_compose_files=elasticsearch_docker_compose_files,
134
167
  timeout=45,
135
168
  pause=1,
136
169
  check=elasticsearch8_responsive,
@@ -140,22 +173,23 @@ async def elasticsearch8_service(
140
173
  password=elasticsearch_password,
141
174
  scheme=elasticsearch_scheme,
142
175
  )
176
+ yield
143
177
 
144
178
 
145
- @pytest.fixture(autouse=False)
179
+ @pytest.fixture(autouse=False, scope="session")
146
180
  async def elasticsearch_service(
147
- docker_services: DockerServiceRegistry,
181
+ elasticsearch_docker_services: DockerServiceRegistry,
148
182
  default_elasticsearch_service_name: str,
149
- docker_compose_files: list[Path],
183
+ elasticsearch_docker_compose_files: list[Path],
150
184
  elasticsearch8_port: int,
151
185
  elasticsearch_database: str,
152
186
  elasticsearch_user: str,
153
187
  elasticsearch_password: str,
154
188
  elasticsearch_scheme: str,
155
- ) -> None:
156
- await docker_services.start(
189
+ ) -> AsyncGenerator[None, None]:
190
+ await elasticsearch_docker_services.start(
157
191
  name=default_elasticsearch_service_name,
158
- docker_compose_files=docker_compose_files,
192
+ docker_compose_files=elasticsearch_docker_compose_files,
159
193
  timeout=45,
160
194
  pause=1,
161
195
  check=elasticsearch8_responsive,
@@ -165,3 +199,4 @@ async def elasticsearch_service(
165
199
  password=elasticsearch_password,
166
200
  scheme=elasticsearch_scheme,
167
201
  )
202
+ yield