|
10 | 10 | import networkx as nx
|
11 | 11 | import json
|
12 | 12 | from pathlib import Path
|
13 |
| -import tempfile |
14 | 13 | from datajoint import errors
|
15 | 14 | from datajoint.errors import ADAPTED_TYPE_SWITCH, FILEPATH_FEATURE_SWITCH
|
16 | 15 | from . import (
|
@@ -176,23 +175,45 @@ def connection_test(connection_root):
|
176 | 175 |
|
177 | 176 |
|
178 | 177 | @pytest.fixture(scope="session")
|
179 |
| -def stores_config(): |
| 178 | +def stores_config(tmpdir_factory): |
180 | 179 | stores_config = {
|
181 |
| - "raw": dict(protocol="file", location=tempfile.mkdtemp()), |
| 180 | + "raw": dict(protocol="file", location=tmpdir_factory.mktemp("raw")), |
182 | 181 | "repo": dict(
|
183 |
| - stage=tempfile.mkdtemp(), protocol="file", location=tempfile.mkdtemp() |
| 182 | + stage=tmpdir_factory.mktemp("repo"), protocol="file", location=tmpdir_factory.mktemp("repo") |
184 | 183 | ),
|
185 | 184 | "repo-s3": dict(
|
186 |
| - S3_CONN_INFO, protocol="s3", location="dj/repo", stage=tempfile.mkdtemp() |
| 185 | + S3_CONN_INFO, protocol="s3", location="dj/repo", stage=tmpdir_factory.mktemp("repo-s3") |
187 | 186 | ),
|
188 |
| - "local": dict(protocol="file", location=tempfile.mkdtemp(), subfolding=(1, 1)), |
| 187 | + "local": dict(protocol="file", location=tmpdir_factory.mktemp("local"), subfolding=(1, 1)), |
189 | 188 | "share": dict(
|
190 | 189 | S3_CONN_INFO, protocol="s3", location="dj/store/repo", subfolding=(2, 4)
|
191 | 190 | ),
|
192 | 191 | }
|
193 | 192 | return stores_config
|
194 | 193 |
|
195 | 194 |
|
| 195 | +@pytest.fixture |
| 196 | +def mock_stores(stores_config): |
| 197 | + og_stores_config = dj.config.get("stores") |
| 198 | + dj.config["stores"] = stores_config |
| 199 | + yield |
| 200 | + if og_stores_config is None: |
| 201 | + del dj.config["stores"] |
| 202 | + else: |
| 203 | + dj.config["stores"] = og_stores_config |
| 204 | + |
| 205 | + |
| 206 | +@pytest.fixture |
| 207 | +def mock_cache(tmpdir_factory): |
| 208 | + og_cache = dj.config.get("cache") |
| 209 | + dj.config["cache"] = tmpdir_factory.mktemp("cache") |
| 210 | + yield |
| 211 | + if og_cache is None: |
| 212 | + del dj.config["cache"] |
| 213 | + else: |
| 214 | + dj.config["cache"] = og_cache |
| 215 | + |
| 216 | + |
196 | 217 | @pytest.fixture
|
197 | 218 | def schema_any(connection_test):
|
198 | 219 | schema_any = dj.Schema(
|
@@ -287,15 +308,12 @@ def schema_adv(connection_test):
|
287 | 308 |
|
288 | 309 |
|
289 | 310 | @pytest.fixture
|
290 |
| -def schema_ext(connection_test, stores_config, enable_filepath_feature): |
| 311 | +def schema_ext(connection_test, enable_filepath_feature, mock_stores, mock_cache): |
291 | 312 | schema = dj.Schema(
|
292 | 313 | PREFIX + "_extern",
|
293 | 314 | context=schema_external.LOCALS_EXTERNAL,
|
294 | 315 | connection=connection_test,
|
295 | 316 | )
|
296 |
| - dj.config["stores"] = stores_config |
297 |
| - dj.config["cache"] = tempfile.mkdtemp() |
298 |
| - |
299 | 317 | schema(schema_external.Simple)
|
300 | 318 | schema(schema_external.SimpleRemote)
|
301 | 319 | schema(schema_external.Seed)
|
|
0 commit comments