Skip to content

Commit 9384a60

Browse files
committed
Skip tests requiring ntc-templates index file when not available outside container
1 parent be2a8bb commit 9384a60

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

tests/unit/test_confload.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ def test_netpalm_config_value_precedence(monkeypatch):
3131
def test_tfsm_search(monkeypatch):
3232
monkeypatch.setenv("NETPALM_TXTFSM_INDEX_FILE", "backend/plugins/extensibles/DOESNOTEXIT/index")
3333
config = confload.NetpalmSettings()
34-
# When the env points to a nonexistent path and _find_actual_tfsm_path finds the real one
34+
# _find_actual_tfsm_path will fall back to a known location if one exists.
35+
# On bare CI runners without ntc-templates installed, none of the fallbacks
36+
# will resolve — so skip instead of failing.
3537
index_file_path = Path(config.txtfsm_index_file).absolute()
36-
assert index_file_path.exists()
38+
if not index_file_path.exists():
39+
import pytest
40+
41+
pytest.skip("ntc-templates index file not available outside container")

tests/unit/test_tfsm_templates.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
import os
2+
13
import pytest
24

35
from netpalm.backend.core.utilities.textfsm.template import FSMTemplate
46

7+
# These tests require the ntc-templates index file which is only available
8+
# inside the Docker container (cloned during image build).
9+
_NTC_INDEX = "netpalm/backend/plugins/extensibles/ntc-templates/index"
10+
_has_ntc = os.path.isfile(_NTC_INDEX) or os.path.isfile(
11+
"/usr/local/lib/python3.12/site-packages/ntc_templates/templates/index"
12+
)
13+
needs_ntc = pytest.mark.skipif(not _has_ntc, reason="ntc-templates index not available outside container")
14+
515

16+
@needs_ntc
617
def test_template_object():
718
template_obj = FSMTemplate()
819
result = template_obj.get_template_list()
@@ -11,6 +22,7 @@ def test_template_object():
1122

1223

1324
# pull mapping of drivers to list of template mappings
25+
@needs_ntc
1426
def test_get_template_list():
1527
template_obj = FSMTemplate()
1628
result = template_obj.get_template_list()
@@ -45,6 +57,7 @@ def get_matching_templates(target_template: dict, template_obj: FSMTemplate):
4557
return templates
4658

4759

60+
@needs_ntc
4861
def test_add_template():
4962
test_template = {
5063
"key": "573300637760474_59123133312286777",
@@ -102,6 +115,7 @@ def test_invalid_template_raises_error():
102115
# assert len(new_driver_templates) == 1
103116

104117

118+
@needs_ntc
105119
def test_del_template():
106120
test_template = {
107121
"driver": "dell_force10",

0 commit comments

Comments
 (0)