Skip to content

Commit 6f37ff6

Browse files
committed
fix: Scope destination fixture and fix 3.14 bug on time.
1 parent 906519a commit 6f37ff6

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

tests/tests_integration/test_api/test_hosted_extractors/conftest.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
SessionWrite,
1212
Source,
1313
)
14-
from cognite.client.utils._text import random_string
15-
1614

1715
@pytest.fixture
1816
def fresh_session(cognite_client: CogniteClient) -> SessionWrite:
@@ -31,16 +29,18 @@ def a_data_set(cognite_client: CogniteClient) -> DataSet:
3129
return created
3230

3331

34-
@pytest.fixture
35-
def one_destination(cognite_client: CogniteClient, fresh_session: SessionWrite) -> Destination:
32+
@pytest.fixture(scope="session")
33+
def one_destination(cognite_client: CogniteClient, os_and_py_version: str) -> Destination:
34+
external_id = f"myNewDestination-{os_and_py_version}"
35+
retrieved = cognite_client.hosted_extractors.destinations.retrieve(external_id, ignore_unknown_ids=True)
36+
if retrieved:
37+
return retrieved
38+
new_session = cognite_client.iam.sessions.create(session_type="ONESHOT_TOKEN_EXCHANGE")
3639
my_dest = DestinationWrite(
37-
external_id=f"myNewDestination-{random_string(10)}",
38-
credentials=fresh_session,
40+
external_id=external_id,
41+
credentials=SessionWrite(nonce=new_session.nonce),
3942
)
40-
created = cognite_client.hosted_extractors.destinations.create(my_dest)
41-
yield created
42-
43-
cognite_client.hosted_extractors.destinations.delete(created.external_id, ignore_unknown_ids=True)
43+
return cognite_client.hosted_extractors.destinations.create(my_dest)
4444

4545

4646
@pytest.fixture(scope="session")

tests/tests_unit/test_utils/test_time.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ def test_month_aligner__ceil(self, dt: datetime, expected: datetime) -> None:
787787
assert expected == MonthAligner.ceil(dt)
788788

789789
def test_month_aligner_ceil__invalid_date(self) -> None:
790-
with pytest.raises(ValueError, match=r"^day is out of range for month$"):
790+
with pytest.raises(ValueError, match=r"day.+range"):
791791
MonthAligner.add_units(datetime(2023, 7, 31), 2) # sept has 30 days
792792

793793
@pytest.mark.parametrize(
@@ -806,7 +806,7 @@ def test_month_aligner__add_unites(self, dt: datetime, n_units: int, expected: d
806806
assert expected == MonthAligner.add_units(dt, n_units)
807807

808808
def test_month_aligner_add_unites__invalid_date(self) -> None:
809-
with pytest.raises(ValueError, match=r"^day is out of range for month$"):
809+
with pytest.raises(ValueError, match=r"day.+range"):
810810
MonthAligner.add_units(datetime(2023, 1, 29), 1) # 2023 = non-leap year
811811

812812

0 commit comments

Comments
 (0)