Skip to content

Commit f3fab83

Browse files
eleanorjboydCopilot
andauthored
Remove unused testresources import and related load_tests function from unittestadapter (#25928)
goal to resolve CI issues Keeps coverage of the testscenarios-based dynamic test-ID pattern (which was the whole point of this fixture). Declaring testtools explicitly replaces the fragile transitive dependency that was causing the CI import failure described in test-scenarios-ci-failure.md. --------- Co-authored-by: Copilot <copilot@github.com>
1 parent 437afb5 commit f3fab83

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

build/test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ flask
1212
fastapi
1313
uvicorn
1414
django
15-
testresources
1615
testscenarios
16+
testtools
1717

1818
# Integrated TensorBoard tests
1919
tensorboard
Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,2 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3-
4-
import os
5-
6-
import testresources
7-
from testscenarios import generate_scenarios
8-
9-
def load_tests(loader, tests, pattern):
10-
this_dir = os.path.dirname(__file__)
11-
mytests = loader.discover(start_dir=this_dir, pattern=pattern)
12-
result = testresources.OptimisingTestSuite()
13-
result.addTests(generate_scenarios(mytests))
14-
result.addTests(generate_scenarios(tests))
15-
return result

python_files/tests/unittestadapter/.data/test_scenarios/tests/test_scene.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4-
from testscenarios import TestWithScenarios
4+
import unittest
5+
6+
from testscenarios import TestWithScenarios, generate_scenarios
7+
8+
9+
def load_tests(loader, standard_tests, pattern): # noqa: ARG001
10+
# Pre-expand ``TestWithScenarios`` scenarios at load time so individual
11+
# scenario-multiplied test IDs (e.g. ``test_operations(add)``) can be
12+
# resolved by ``unittest.TestLoader.loadTestsFromName``. Without this,
13+
# ``TestWithScenarios`` only multiplies scenarios at ``run()`` time and
14+
# loading a specific scenario by name raises ``AttributeError``.
15+
result = unittest.TestSuite()
16+
result.addTests(generate_scenarios(standard_tests))
17+
return result
18+
519

620
class TestMathOperations(TestWithScenarios):
721
scenarios = [
822
('add', {'test_id': 'test_add', 'a': 5, 'b': 3, 'expected': 8}),
923
('subtract', {'test_id': 'test_subtract', 'a': 5, 'b': 3, 'expected': 2}),
10-
('multiply', {'test_id': 'test_multiply', 'a': 5, 'b': 3, 'expected': 15})
24+
('multiply', {'test_id': 'test_multiply', 'a': 5, 'b': 3, 'expected': 15}),
1125
]
1226
a: int = 0
1327
b: int = 0

0 commit comments

Comments
 (0)