Skip to content

Commit e3a96ae

Browse files
committed
Prefix fixtures to prevent conflicts until pytest-dev/pytest#3966 is resolved.
1 parent a6c3fca commit e3a96ae

File tree

4 files changed

+600
-621
lines changed

4 files changed

+600
-621
lines changed

README.md

+76-77
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Overview
44

5-
Pytest fixtures to instantiate and populated local docker GIT SCMs, using [lovely-pytest-docker](https://pypi.org/project/lovely-pytest-docker), for testing.
5+
Pytest fixtures to instantiate and populated local GIT SCMs, using [lovely-pytest-docker](https://pypi.org/project/lovely-pytest-docker), for testing.
66

77
## Getting Started
88

@@ -21,12 +21,12 @@ All fixtures should be automatically included via the <tt>pytest11</tt> entry po
2121
import pytest
2222
import subprocess
2323
from pathlib import Path
24-
from pytest_docker_git_fixtures import DockerGITInsecure, DockerGITSecure # Optional, for typing
24+
from pytest_git_fixtures import GITInsecure, GITSecure # Optional, for typing
2525

26-
@pytest.mark.create_repo("test_docker_git_secure")
26+
@pytest.mark.create_repo("test_git_secure")
2727
@pytest.mark.mirror_repo("https://github.com/crashvb/shim-bind.git")
28-
def test_docker_git_secure(docker_git_secure: DockerGITSecure, tmp_path: Path):
29-
uri = f"https://{docker_git_secure.endpoint}/secure/shim-bind.git"
28+
def test_git_secure(git_secure: GITSecure, tmp_path: Path):
29+
uri = f"https://{git_secure.endpoint}/secure/shim-bind.git"
3030
path = tmp_path.join("local-clone")
3131
subprocess.run(
3232
["git", "clone", uri, str(path)],
@@ -36,9 +36,9 @@ def test_docker_git_secure(docker_git_secure: DockerGITSecure, tmp_path: Path):
3636
)
3737
assert path.joinpath("README.md").exists()
3838

39-
@pytest.mark.create_repo("test_docker_git_insecure")
40-
def test_docker_git_insecure(docker_git_insecure: DockerGITInsecure, tmp_path: Path):
41-
uri = f"https://{docker_git_insecure.endpoint}/insecure/test_docker_git_insecure.git"
39+
@pytest.mark.create_repo("test_git_insecure")
40+
def test_git_insecure(git_insecure: GITInsecure, tmp_path: Path):
41+
uri = f"https://{git_insecure.endpoint}/insecure/test_git_insecure.git"
4242
path = tmp_path.join("local-clone")
4343
subprocess.run(
4444
["git", "clone", uri, str(path)],
@@ -58,7 +58,7 @@ The `create_repo` and `mirror_repo` marks can optionally be added to stage repos
5858
### From [pypi.org](https://pypi.org/project/pytest-docker-git-fixtures/)
5959

6060
```
61-
$ pip install pytest_docker_git_fixtures
61+
$ pip install pytest_git_fixtures
6262
```
6363

6464
### From source code
@@ -73,25 +73,17 @@ $ python -m pip install --editable .[dev]
7373

7474
## <a name="fixtures"></a>Fixtures
7575

76-
### <a name="docker_compose_insecure"></a> docker_compose_insecure
76+
### <a name="git_auth_header"></a> git_auth_header
7777

78-
This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically <tt>tests/docker-compose.yml</tt>) that contains the <tt>pytest-docker-git-insecure</tt> service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the insecure docker GIT service.
78+
Retrieves an HTTP basic authentication header that is populated with credentials that can access the secure GIT service. The credentials are retrieved from the [git_password](#git_password) and [git_username](#git_username) fixtures.
7979

80-
### <a name="docker_compose_secure"></a> docker_compose_secure
80+
### <a name="git_cacerts"></a> git_cacerts
8181

82-
This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically <tt>tests/docker-compose.yml</tt>) that contains the <tt>pytest-docker-git-secure</tt> service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the secure docker GIT service; however, unlike the configuration returned by the [docker_compose_insecure](#docker_compose_insecure) fixture, this configuration will be treated as a template; the <tt>$PATH_CERTIFICATE</tt>, <tt>$PATH_HTPASSWD</tt>, and <tt>$PATH_KEY</tt> tokens will be populated with the absolute paths provided by the [docker_git_certs](#docker_git_certs) and [docker_git_htpasswd](#docker_git_htpasswd) fixtures, as appropriate.
82+
Locates a user-defined CA trust store (<tt>tests/cacerts</tt>) to use to verify connections to the secure GIT service. If one cannot be located, a temporary trust store is created containing certificates from <tt>certifi</tt> and the [git_certs](#git_certs) fixture. This fixture is used to instantiate the secure GIT service.
8383

84-
### <a name="docker_git_auth_header"></a> docker_git_auth_header
84+
### <a name="git_certs"></a> git_certs
8585

86-
Retrieves an HTTP basic authentication header that is populated with credentials that can access the secure docker GIT service. The credentials are retrieved from the [docker_git_password](#docker_git_password) and [docker_git_username](#docker_git_username) fixtures.
87-
88-
### <a name="docker_git_cacerts"></a> docker_git_cacerts
89-
90-
Locates a user-defined CA trust store (<tt>tests/cacerts</tt>) to use to verify connections to the secure docker GIT service. If one cannot be located, a temporary trust store is created containing certificates from <tt>certifi</tt> and the [docker_git_certs](#docker_git_certs) fixture. This fixture is used to instantiate the secure docker GIT service.
91-
92-
### <a name="docker_git_certs"></a> docker_git_certs
93-
94-
Returns the paths of the self-signed certificate authority certificate, certificate, and private key that are used by the secure docker GIT service. This fixture is used to instantiate the secure docker GIT service.
86+
Returns the paths of the self-signed certificate authority certificate, certificate, and private key that are used by the secure GIT service. This fixture is used to instantiate the secure GIT service.
9587

9688
#### NamedTuple Fields
9789

@@ -102,25 +94,25 @@ The following fields are defined in the tuple provided by this fixture:
10294
* **certificate** - Path to the certificate.
10395
* **private_key** - Path to the private key.
10496

105-
Typing is provided by `pytest_docker_git_fixtures.DockerGITCerts`.
97+
Typing is provided by `pytest_git_fixtures.GITCerts`.
10698

107-
### <a name="docker_git_hwpasswd"></a> docker_git_htpasswd
99+
### <a name="git_hwpasswd"></a> git_htpasswd
108100

109-
Provides the path to a htpasswd file that is used by the secure docker GIT service. If a user-defined htpasswd file (<tt>tests/htpasswd</tt>) can be located, it is used. Otherwise, a temporary htpasswd file is created using credentials from the [docker_git_password](#docker_git_password) and [docker_git_username](#docker_git_username) fixtures. This fixture is used to instantiate the secure docker GIT service.
101+
Provides the path to a htpasswd file that is used by the secure GIT service. If a user-defined htpasswd file (<tt>tests/htpasswd</tt>) can be located, it is used. Otherwise, a temporary htpasswd file is created using credentials from the [git_password](#git_password) and [git_username](#git_username) fixtures. This fixture is used to instantiate the secure GIT service.
110102

111-
### <a name="docker_git_insecure"></a> docker_git_insecure
103+
### <a name="git_insecure"></a> git_insecure
112104

113-
Configures and instantiates a docker GIT without TLS or authentication.
105+
Configures and instantiates a GIT without TLS or authentication.
114106

115107
```python
116108
import pytest
117109
import subprocess
118110
from pathlib import Path
119-
from pytest_docker_git_fixtures import DockerGITInsecure # Optional, for typing
111+
from pytest_git_fixtures import GITInsecure # Optional, for typing
120112

121-
@pytest.mark.create_repo("test_docker_git_insecure")
122-
def test_docker_git_insecure(docker_git_insecure: DockerGITInsecure, tmp_path: Path):
123-
uri = f"https://{docker_git_insecure.endpoint}/insecure/test_docker_git_insecure.git"
113+
@pytest.mark.create_repo("test_git_insecure")
114+
def test_git_insecure(git_insecure: GITInsecure, tmp_path: Path):
115+
uri = f"https://{git_insecure.endpoint}/insecure/test_git_insecure.git"
124116
path = tmp_path.join("local-clone")
125117
subprocess.run(
126118
["git", "clone", uri, str(path)],
@@ -137,29 +129,29 @@ The following fields are defined in the tuple provided by this fixture:
137129

138130
* **created_repos** - The list of created repositories.
139131
* **docker_compose** - Path to the fully instantiated docker-compose configuration.
140-
* **endpoint** - Endpoint of the insecure docker GIT service.
132+
* **endpoint** - Endpoint of the insecure GIT service.
141133
* **mirrored_repos** - The list of mirrored repositories.
142134
* **service_name** - Name of the service within the docker-compose configuration.
143135

144-
Typing is provided by `pytest_docker_git_fixtures.DockerGITInsecure`.
136+
Typing is provided by `pytest_git_fixtures.GITInsecure`.
145137

146-
### <a name="docker_git_password"></a> docker_git_password
138+
### <a name="git_password"></a> git_password
147139

148-
Provides a generated password to use for authentication to the secure docker GIT service.
140+
Provides a generated password to use for authentication to the secure GIT service.
149141

150-
### <a name="docker_git_secure"></a> docker_git_secure
142+
### <a name="git_secure"></a> git_secure
151143

152-
Configures and instantiates a TLS enabled docker GIT with HTTP basic authorization.
144+
Configures and instantiates a TLS enabled GIT with HTTP basic authorization.
153145

154146
```python
155147
import pytest
156148
import subprocess
157149
from pathlib import Path
158-
from pytest_docker_git_fixtures import DockerGITSecure # Optional, for typing
150+
from pytest_git_fixtures import GITSecure # Optional, for typing
159151

160152
@pytest.mark.mirror_repo("https://github.com/crashvb/shim-bind.git")
161-
def test_docker_git_secure(docker_git_secure: DockerGITSecure, tmp_path: Path):
162-
uri = f"https://{docker_git_secure.endpoint}/secure/shim-bind.git"
153+
def test_git_secure(git_secure: GITSecure, tmp_path: Path):
154+
uri = f"https://{git_secure.endpoint}/secure/shim-bind.git"
163155
path = tmp_path.join("local-clone")
164156
subprocess.run(
165157
["git", "clone", uri, str(path)],
@@ -174,43 +166,50 @@ def test_docker_git_secure(docker_git_secure: DockerGITSecure, tmp_path: Path):
174166

175167
The following fields are defined in the tuple provided by this fixture:
176168

177-
* **auth_header** - from [docker_git_auth_header](#docker_git_auth_header).
178-
* **cacerts** - from [docker_git_cacerts](#docker_git_cacerts).
179-
* **certs** - from [docker_git_certs](#docker_git_certs).
169+
* **auth_header** - from [git_auth_header](#git_auth_header).
170+
* **cacerts** - from [git_cacerts](#git_cacerts).
171+
* **certs** - from [git_certs](#git_certs).
180172
* **created_repos** - The list of created repositories.
181173
* **docker_compose** - Path to the fully instantiated docker-compose configuration.
182-
* **endpoint** - Endpoint of the secure docker GIT service.
183-
* **htpasswd** - from [docker_git_htpasswd](#docker_git_htpasswd)
174+
* **endpoint** - Endpoint of the secure GIT service.
175+
* **htpasswd** - from [git_htpasswd](#git_htpasswd)
184176
* **mirrored_repos** - The list of mirrored repositories.
185-
* **password** - from [docker_git_password](#docker_git_password).
177+
* **password** - from [git_password](#git_password).
186178
* **service_name** - Name of the service within the docker-compose configuration.
187-
* **ssl_context** - from [docker_git_ssl_context](#docker_git_ssl_context).
188-
* **username** - from [docker_git_username](#docker_git_username).
179+
* **ssl_context** - from [git_ssl_context](#git_ssl_context).
180+
* **username** - from [git_username](#git_username).
181+
182+
Typing is provided by `pytest_git_fixtures.GITSecure`.
183+
184+
### <a name="git_ssl_context"></a> git_ssl_context
185+
186+
Provides an SSL context containing the CA trust store from the [git_cacerts](#git_cacerts) fixture.
189187

190-
Typing is provided by `pytest_docker_git_fixtures.DockerGITSecure`.
188+
### <a name="git_username"></a> git_username
191189

192-
### <a name="docker_git_ssl_context"></a> docker_git_ssl_context
190+
Provides a generated username to use for authentication to the secure GIT service.
193191

194-
Provides an SSL context containing the CA trust store from the [docker_git_cacerts](#docker_git_cacerts) fixture.
192+
### <a name="pdgf_docker_compose_insecure"></a> pdgf_docker_compose_insecure
195193

196-
### <a name="docker_git_username"></a> docker_git_username
194+
This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically <tt>tests/docker-compose.yml</tt>) that contains the <tt>pytest-docker-git-insecure</tt> service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the insecure GIT service.
197195

198-
Provides a generated username to use for authentication to the secure docker GIT service.
196+
### <a name="pdgf_docker_compose_secure"></a> docker_compose_secure
199197

198+
This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically <tt>tests/docker-compose.yml</tt>) that contains the <tt>pytest-docker-git-secure</tt> service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the secure GIT service; however, unlike the configuration returned by the [pdgf_docker_compose_insecure](#pdgf_docker_compose_insecure) fixture, this configuration will be treated as a template; the <tt>$PATH_CERTIFICATE</tt>, <tt>$PATH_HTPASSWD</tt>, and <tt>$PATH_KEY</tt> tokens will be populated with the absolute paths provided by the [git_certs](#git_certs) and [git_htpasswd](#git_htpasswd) fixtures, as appropriate.
200199
## <a name="markers"></a>Markers
201200

202201
### pytest.mark.create_repo
203202

204-
This marker specifies the GIT repository(ies) that should be initialized within the docker GIT service(s) prior to testing. It can ...
203+
This marker specifies the GIT repository(ies) that should be initialized within the GIT service(s) prior to testing. It can ...
205204

206205
... decorate individual tests:
207206

208207
```python
209208
import pytest
210-
from pytest_docker_git_fixtures import DockerGITSecure # Optional, for typing
209+
from pytest_git_fixtures import GITSecure # Optional, for typing
211210

212-
@pytest.mark.create_repo("test_docker_git_secure")
213-
def test_docker_git_secure(docker_git_secure: DockerGITSecure):
211+
@pytest.mark.create_repo("test_git_secure")
212+
def test_git_secure(git_secure: GITSecure):
214213
...
215214
```
216215

@@ -238,64 +237,64 @@ A helper function, `get_created_repos`, is included for test scenarios that wis
238237

239238
```python
240239
import pytest
241-
from pytest_docker_git_fixtures import DockerGITSecure, get_created_repos
240+
from pytest_git_fixtures import GITSecure, get_created_repos
242241

243-
@pytest.mark.create_repo("test_docker_git_secure")
244-
def test_docker_git_secure(docker_git_secure: DockerGITSecure, request):
242+
@pytest.mark.create_repo("test_git_secure")
243+
def test_git_secure(git_secure: GITSecure, request):
245244
name = get_created_repos(request)[0]
246245
```
247246

248247
### pytest.mark.mirror_repo
249248

250-
Similarly to create_repo, this marker specifies the GIT repository(ies) that should be replicated to the docker GIT service(s) prior to testing.
249+
Similarly to create_repo, this marker specifies the GIT repository(ies) that should be replicated to the GIT service(s) prior to testing.
251250

252251
Likewise, there is a `get_mirrored_repos` helper function.
253252

254253
## <a name="enumerated_fixtures"></a>Enumerated Fixtures
255254

256-
It is possible to instantiate multiple GIT instances using the corresponding enumerated fixtures. All [fixtures](#fixtures) listed above have _*_list_ (e.g. `docker_git_secure` -> `docker_git_secure_list`) versions that will return enumerated lists of corresponding data type.
255+
It is possible to instantiate multiple GIT instances using the corresponding enumerated fixtures. All [fixtures](#fixtures) listed above have _*_list_ (e.g. `git_secure` -> `git_secure_list`) versions that will return enumerated lists of corresponding data type.
257256

258257
For example:
259258

260259
```python
261260
import requests
262261
from typing import List # Optional, for typing
263-
from pytest_docker_git_fixtures import DockerGITSecure # Optional, for typing
262+
from pytest_git_fixtures import GITSecure # Optional, for typing
264263

265-
def test_docker_git_secure_list(docker_git_secure_list: List[DockerGITSecure]):
266-
for docker_git_secure in docker_git_secure_list:
264+
def test_git_secure_list(git_secure_list: List[GITSecure]):
265+
for git_secure in git_secure_list:
267266
# Default listener ...
268267
response = requests.get(
269-
f"https://{docker_git_secure.endpoint}/",
270-
headers=docker_git_secure.auth_header,
271-
verify=str(docker_git_secure.cacerts),
268+
f"https://{git_secure.endpoint}/",
269+
headers=git_secure.auth_header,
270+
verify=str(git_secure.cacerts),
272271
)
273272
assert response.status_code == 200
274273
assert response.content == b"pytest-docker-git-fixtures-docker\n"
275274
```
276275

277-
It is possible to use both singular and enumerated fixtures within the same test context; however, the same values will be returned for the singular fixture as the first enumerated list value (i.e. docker_git_secure == docker_git_secure_list[0]). To avoid complications with lower layers, mainly docker-compose, and to allow for this interchangeability, caching is used internally.
276+
It is possible to use both singular and enumerated fixtures within the same test context; however, the same values will be returned for the singular fixture as the first enumerated list value (i.e. git_secure == git_secure_list[0]). To avoid complications with lower layers, mainly docker-compose, and to allow for this interchangeability, caching is used internally.
278277

279-
By default, the scale factor of the enumerated instances is set to one (n=1). This value can be changed by overriding the `pdrf_scale_factor` fixture, as follows:
278+
By default, the scale factor of the enumerated instances is set to one (n=1). This value can be changed by overriding the `pdgf_scale_factor` fixture, as follows:
280279

281280
```python
282281
import pytest
283282

284283
@pytest.fixture(scope="session")
285-
def pdrf_scale_factor() -> int:
284+
def pdgf_scale_factor() -> int:
286285
return 4
287286
```
288287

289-
This fixture will be used to scale both the insecure and secure docker GIT SCMs.
288+
This fixture will be used to scale both the insecure and secure GIT SCMs.
290289

291290
## <a name="limitations"></a>Limitations
292291

293292
1. All the fixtures provided by this package are <tt>session</tt> scoped; and will only be executed once per test execution.
294-
2. The `create_repo`, and `mirror_repo` markers are processed as part of the `docker_git_insecure` and `docker_git_secure` fixtures. As such:
293+
2. The `create_repo`, and `mirror_repo` markers are processed as part of the `git_insecure` and `git_secure` fixtures. As such:
295294
* _all_ markers will be aggregated during initialization of the session, and processed prior test execution.
296-
* Initialized and mirror repositories will be applied to both the insecure and secure docker GIT SCMs, if both are instantiated.
297-
3. At most 10 insecure and 10 secure docker GIT SCMs are supported using the embedded docker compose.
298-
4. It is not currently possible to specify into which enumerated SCM instances repositories should be applied. As such, and for backwards compatibility, they will only be applied into the first instance of each of the insecure and secure docker GIT SCMs.
295+
* Initialized and mirror repositories will be applied to both the insecure and secure GIT SCMs, if both are instantiated.
296+
3. At most 10 insecure and 10 secure GIT SCMs are supported using the embedded docker compose.
297+
4. It is not currently possible to specify into which enumerated SCM instances repositories should be applied. As such, and for backwards compatibility, they will only be applied into the first instance of each of the insecure and secure GIT SCMs.
299298

300299
## Development
301300

0 commit comments

Comments
 (0)