Skip to content

Commit 9de3977

Browse files
committed
revert changes to helpers, documented refactor request instead
Signed-off-by: Ganyu (Bruce) Xu <[email protected]>
1 parent 0f5afc2 commit 9de3977

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

tests/helpers.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,29 +142,31 @@ def is_sig_stfl_enabled_by_name(name):
142142
return True
143143
return False
144144

145+
# TODO: this function needs a refactor because the scan logic currently applies
146+
# re.findall to all args/kwargs in the wrapped function. If the function takes
147+
# a non-string argument, re.findall will raise a TypeError, which is
148+
# undesirable. It can also cause incorrect skipping if the wrapped function
149+
# takes some string argument that unintentionally matches the regex.
150+
# Instead, I prefer replacing this decorator with a regular function that returns
151+
# a boolean indicating whether a KEM/SIG/STFL_SIG name matches the env var
152+
# SKIP_ALGS, then let the caller decide whether to call pytest.skip.
145153
def filtered_test(func):
146-
funcname = func.__name__[len("test_") :]
154+
funcname = func.__name__[len("test_"):]
147155

148156
@functools.wraps(func)
149157
def wrapper(*args, **kwargs):
150-
if ("SKIP_ALGS" in os.environ) and len(os.environ["SKIP_ALGS"]) > 0:
151-
for algexp in os.environ["SKIP_ALGS"].split(","):
158+
if ('SKIP_ALGS' in os.environ) and len(os.environ['SKIP_ALGS'])>0:
159+
for algexp in os.environ['SKIP_ALGS'].split(','):
152160
for arg in args:
153-
if isinstance(arg, str) and len(re.findall(algexp, arg)) > 0:
161+
if len(re.findall(algexp, arg))>0:
154162
pytest.skip("Test disabled by alg filter")
155163
for arg in kwargs:
156-
if (
157-
isinstance(kwargs[arg], str)
158-
and len(re.findall(algexp, kwargs[arg])) > 0
159-
):
164+
if len(re.findall(algexp, kwargs[arg]))>0:
160165
pytest.skip("Test disabled by alg filter")
161-
if ("SKIP_TESTS" in os.environ) and (
162-
funcname in os.environ["SKIP_TESTS"].lower().split(",")
163-
):
166+
if ('SKIP_TESTS' in os.environ) and (funcname in os.environ['SKIP_TESTS'].lower().split(',')):
164167
pytest.skip("Test disabled by filter")
165168
else:
166169
return func(*args, **kwargs)
167-
168170
return wrapper
169171

170172
# So far, build dir name has been hard coded to "build".

tests/test_acvp_vectors.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
@helpers.filtered_test
3939
@pytest.mark.parametrize("kem_name", helpers.available_kems_by_name())
4040
def test_acvp_vec_kem_keygen(kem_name):
41-
# TODO: this logic feels awkward
41+
# TODO: this logic feels backwards. It will instantiate kem_name with all
42+
# possible names, then filter out the overwhelming majority of them that are
43+
# "not ML-KEM". This creates a lot of skipped tests that, despite not having
44+
# much performance penalty, pollute the pytest output.
4245
if not (helpers.is_kem_enabled_by_name(kem_name)):
4346
pytest.skip("Not enabled")
4447
if not (kem_name in ml_kem):

0 commit comments

Comments
 (0)