Skip to content

Commit f344338

Browse files
author
Nissan Pow
committed
fix tests (merged)
1 parent 2222648 commit f344338

File tree

3 files changed

+121
-84
lines changed

3 files changed

+121
-84
lines changed

test/data/s3/conftest.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pytest
2+
from metaflow import current
3+
from .. import S3ROOT
4+
5+
# S3ROOT variants for testing both with and without trailing slash
6+
S3ROOT_VARIANTS = [S3ROOT.rstrip("/"), S3ROOT if S3ROOT.endswith("/") else S3ROOT + "/"]
7+
8+
9+
@pytest.fixture(params=S3ROOT_VARIANTS, ids=["no_slash", "with_slash"])
10+
def s3root(request):
11+
"""
12+
Fixture that provides S3ROOT with and without trailing slash.
13+
14+
This ensures tests work correctly regardless of whether the s3root
15+
has a trailing slash or not.
16+
"""
17+
return request.param
18+
19+
20+
@pytest.fixture(autouse=True)
21+
def reset_current_env():
22+
"""
23+
Fixture to ensure the metaflow current environment is clean between tests.
24+
25+
This prevents test pollution when tests manipulate the global current state.
26+
The fixture runs automatically for all tests in this directory.
27+
"""
28+
# Setup: Save the current state (if any)
29+
saved_state = getattr(current, "_flow", None)
30+
31+
yield
32+
33+
# Teardown: Reset current to initial state
34+
# Clear any environment that was set during the test
35+
if hasattr(current, "_flow"):
36+
current._flow = saved_state

test/data/s3/s3_data.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def data(self):
197197

198198
@property
199199
def url(self):
200-
return os.path.join(S3ROOT, self.key)
200+
return self.key
201201

202202

203203
def _format_test_cases(dataset, meta=None, ranges=None):
@@ -485,11 +485,6 @@ def pytest_put_blobs_case(meta=None):
485485

486486
def ensure_test_data():
487487
# update S3ROOT in __init__.py to get a fresh set of data
488-
if S3ROOT is None:
489-
print(
490-
"S3ROOT is not set. Set METAFLOW_S3_TEST_ROOT environment variable to run S3 tests."
491-
)
492-
return
493488
print("Ensuring that test data exists at %s" % S3ROOT)
494489
mark = urlparse(os.path.join(S3ROOT, "ALL_OK"))
495490
try:

0 commit comments

Comments
 (0)