Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/cas/test_intentservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def test_intentservice_reject_load():
def test_invalid_intents_rejected(invalid_intent):
import garak.services.intentservice

garak._config.load_config()
garak.services.intentservice.load()

with pytest.raises(ValueError) as excinfo:
s = garak.services.intentservice.get_intent_stubs(invalid_intent)
assert str(excinfo.value).startswith("Not a valid")
Expand Down
37 changes: 37 additions & 0 deletions tests/cas/test_intentservice_state_reset.py

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no reason to have a test file to test testing only functionality.

At best test_intentservice_load_populates_state asserts are functionality that should be added to test_load_intentservice in test_intentservice.py.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import garak._config


def test_intentservice_load_populates_state():
import garak.services.intentservice

garak.services.intentservice.is_loaded = False
garak.services.intentservice.intent_typology = {}
garak.services.intentservice.intent_detectors = {}
garak.services.intentservice.intents_active = set()

garak._config.load_config()
garak.services.intentservice.load()

assert garak.services.intentservice.is_loaded, "load() must set is_loaded"
assert garak.services.intentservice.intent_typology, "load() must load the typology"
assert garak.services.intentservice.intents_active, "load() must activate intents"


def test_intentservice_state_reset_between_tests():
import garak.services.intentservice

assert not garak.services.intentservice.is_loaded, (
"intentservice must not stay loaded across tests"
)
assert garak.services.intentservice.intent_typology == {}, (
"intent typology must be reset between tests"
)
assert garak.services.intentservice.intent_detectors == {}, (
"intent detector mapping must be reset between tests"
)
assert garak.services.intentservice.intents_active == set(), (
"active intents must be reset between tests"
)
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ def reload():
reload()


@pytest.fixture(autouse=True)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting this to autouse at the root of the test path will cause it to run for every test. Is that really what it should do?

def clear_intentservice_state(request):
"""Reset intentservice for each test"""

def clear_intentservice_state():
from garak.services import intentservice

intentservice.is_loaded = False
intentservice.intent_typology = {}
intentservice.intent_detectors = {}
intentservice.intents_active = set()

request.addfinalizer(clear_intentservice_state)


def pytest_configure(config):
config.addinivalue_line(
"markers",
Expand Down