Skip to content

Commit e299f33

Browse files
committed
refactor(humanitix): drop importlib boilerplate and os.chdir from tests
With tests/conftest.py now putting the integration root on sys.path and the workspace conftest.py patching Integration.load to find config.json from the caller's directory, tests can import the integration with a plain 'from humanitix import humanitix'. Removes: - The importlib.util.spec_from_file_location dance in both test files. - The process-global os.chdir(_parent) calls (the integration test file did not restore cwd, leaving it inside humanitix/ for any test file collected after it). - The legacy tests/context.py shim from the pre-SDK-2.0 testbed. Matches the simpler pattern used in PR #280 (supadata), PR #289 (google-sheets), and PR #307 (coda).
1 parent e179dba commit e299f33

3 files changed

Lines changed: 10 additions & 48 deletions

File tree

humanitix/tests/context.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

humanitix/tests/test_humanitix_integration.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,12 @@
1212
"""
1313

1414
import os
15-
import sys
16-
import importlib
1715

18-
_parent = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
19-
sys.path.insert(0, _parent)
16+
import pytest
17+
from unittest.mock import MagicMock, AsyncMock
18+
from autohive_integrations_sdk import FetchResponse
2019

21-
import pytest # noqa: E402
22-
from unittest.mock import MagicMock, AsyncMock # noqa: E402
23-
from autohive_integrations_sdk import FetchResponse # noqa: E402
24-
25-
os.chdir(_parent)
26-
_spec = importlib.util.spec_from_file_location("humanitix_mod_integration", os.path.join(_parent, "humanitix.py"))
27-
_mod = importlib.util.module_from_spec(_spec)
28-
# Register as "humanitix" so that actions/*.py can `from humanitix import humanitix`
29-
sys.modules.setdefault("humanitix", _mod)
30-
_spec.loader.exec_module(_mod)
31-
32-
humanitix = _mod.humanitix
20+
from humanitix import humanitix
3321

3422
pytestmark = pytest.mark.integration
3523

humanitix/tests/test_humanitix_unit.py

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,12 @@
44
Uses mocked context.fetch to test all actions without making real API calls.
55
"""
66

7-
import os
8-
import sys
9-
import importlib
10-
import importlib.util
11-
12-
_parent = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
13-
sys.path.insert(0, _parent)
14-
15-
import pytest # noqa: E402
16-
from unittest.mock import AsyncMock, MagicMock # noqa: E402
17-
from autohive_integrations_sdk import FetchResponse # noqa: E402
18-
from autohive_integrations_sdk.integration import ResultType # noqa: E402
19-
20-
_original_cwd = os.getcwd()
21-
os.chdir(_parent)
22-
_spec = importlib.util.spec_from_file_location("humanitix_mod", os.path.join(_parent, "humanitix.py"))
23-
_mod = importlib.util.module_from_spec(_spec)
24-
# Register as "humanitix" so that actions/*.py can `from humanitix import humanitix`
25-
sys.modules["humanitix"] = _mod
26-
_spec.loader.exec_module(_mod)
27-
os.chdir(_original_cwd)
28-
sys.modules["humanitix_mod"] = _mod
29-
30-
humanitix = _mod.humanitix
7+
import pytest
8+
from unittest.mock import AsyncMock, MagicMock
9+
from autohive_integrations_sdk import FetchResponse
10+
from autohive_integrations_sdk.integration import ResultType
11+
12+
from humanitix import humanitix
3113

3214
pytestmark = pytest.mark.unit
3315

0 commit comments

Comments
 (0)