| 222 | |
| 223 | @pytest.fixture(scope="session") |
| 224 | def docker_services(tmp_path_factory, request): |
| 225 | from filelock import FileLock |
| 226 | |
| 227 | if os.environ.get("CI") and os.name == "nt": |
| 228 | pytest.skip("disabled for Windows on CI") |
| 229 | |
| 230 | try: |
| 231 | subprocess.check_output( # noqa: S602 |
| 232 | "docker ps", # noqa: S607 |
| 233 | stderr=subprocess.STDOUT, |
| 234 | shell=True, |
| 235 | ) |
| 236 | except subprocess.CalledProcessError as err: |
| 237 | out = (err.output or b"").decode("utf-8") |
| 238 | pytest.skip(f"docker is not installed or the daemon is not running: {out}") |
| 239 | |
| 240 | try: |
| 241 | cmd = "docker-compose version" |
| 242 | subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) # noqa: S602 |
| 243 | except subprocess.CalledProcessError as err: |
| 244 | out = (err.output or b"").decode("utf-8") |
| 245 | pytest.skip(f"docker-compose is not installed: {out}") |
| 246 | |
| 247 | # making sure we don't accidentally launch docker-compose in parallel, |
| 248 | # as it might result in network conflicts. Inspired by: |
| 249 | # https://github.com/pytest-dev/pytest-xdist#making-session-scoped-fixtures-execute-only-once |
| 250 | lockfile = tmp_path_factory.getbasetemp().parent / "docker-compose.lock" |
| 251 | with FileLock(os.fspath(lockfile)): |
| 252 | return request.getfixturevalue("docker_services") |
| 253 | |
| 254 | |
| 255 | @pytest.fixture |