Skip to content

Commit e40d942

Browse files
committed
Various housekeeping
1 parent 0510d52 commit e40d942

File tree

8 files changed

+91
-32
lines changed

8 files changed

+91
-32
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update Pytest-httpx and set all responses as reusable

changelog/+pytest.housekeeping.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a fixture to always reset some environment variables before running tests

infrahub_sdk/yaml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class InfrahubFileData(BaseModel):
2525
api_version: InfrahubFileApiVersion = Field(InfrahubFileApiVersion.V1, alias="apiVersion")
2626
kind: InfrahubFileKind
2727
spec: dict
28-
metadata: dict | None = Field(default_factory=dict)
28+
metadata: dict = Field(default_factory=dict)
2929

3030

3131
class LocalFile(BaseModel):

poetry.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import asyncio
2+
import os
23

34
import pytest
45

56
from infrahub_sdk.ctl import config
67

78
pytest_plugins = ["pytester"]
89

10+
ENV_VARS_TO_CLEAN = ["INFRAHUB_ADDRESS", "INFRAHUB_TOKEN", "INFRAHUB_BRANCH", "INFRAHUB_USERNAME", "INFRAHUB_PASSWORD"]
11+
912

1013
@pytest.fixture(scope="session")
1114
def event_loop():
@@ -20,3 +23,19 @@ def event_loop():
2023
def execute_before_any_test():
2124
config.SETTINGS.load_and_exit()
2225
config.SETTINGS.active.server_address = "http://mock"
26+
27+
28+
@pytest.fixture(scope="session", autouse=True)
29+
def clean_env_vars():
30+
"""Cleans the environment variables before any test is run."""
31+
original_values = {}
32+
for name in ENV_VARS_TO_CLEAN:
33+
original_values[name] = os.environ.get(name)
34+
if original_values[name] is not None:
35+
del os.environ[name]
36+
37+
yield
38+
39+
for name in ENV_VARS_TO_CLEAN:
40+
if original_values[name] is not None:
41+
os.environ[name] = original_values[name]

tests/unit/sdk/checks/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ async def mock_gql_query_my_query(httpx_mock: HTTPXMock) -> HTTPXMock:
1717
method="POST",
1818
json=response,
1919
url="http://localhost:8000/api/query/my_query?branch=main&update_group=false",
20+
is_reusable=True,
2021
)
2122
return httpx_mock

0 commit comments

Comments
 (0)