|
1 | 1 | # Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | # Licensed under the MIT License. |
3 | 3 |
|
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 | + |
5 | 19 |
|
6 | 20 | class TestMathOperations(TestWithScenarios): |
7 | 21 | scenarios = [ |
8 | 22 | ('add', {'test_id': 'test_add', 'a': 5, 'b': 3, 'expected': 8}), |
9 | 23 | ('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}), |
11 | 25 | ] |
12 | 26 | a: int = 0 |
13 | 27 | b: int = 0 |
|
0 commit comments