Skip to content

Commit f8a633e

Browse files
Fixed python test runner code to error out if there are 0 test runs (#34164)
* Create python_test_arguments.txt * Fixed runner code that 0 runs are an error * Restyled by autopep8 * Update hello_test.py * Update python_test_arguments.txt * Update python.md * Update python.md * Delete docs/testing/python_test_arguments.txt * Restyled by prettier-markdown * Update python.md * Update python.md * Update run_python_test.py * Restyled by prettier-markdown * Update python.md * Restyled by prettier-markdown --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 7557e54 commit f8a633e

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

docs/testing/python.md

+65-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Python tests located in src/python_testing
1919

2020
## Writing Python tests
2121

22+
- Defining arguments in the test script
23+
- In order to streamline the configuration and execution of tests, it is
24+
essential to define arguments at the top of the test script. This
25+
section should include various parameters and their respective values,
26+
which will guide the test runner on how to execute the tests.
2227
- All test classes inherit from MatterBaseTest in
2328
[matter_testing_support.py](https://github.com/project-chip/connectedhomeip/blob/master/src/python_testing/matter_testing_support.py)
2429
- support for commissioning using the python controller
@@ -36,11 +41,17 @@ Python tests located in src/python_testing
3641
- Use Mobly assertions for failing tests
3742
- self.step() along with a steps\_ function to mark test plan steps for cert
3843
tests
39-
-
4044

4145
### A simple test
4246

4347
```
48+
# test-runner-runs: run1
49+
# test-runner-run/run1/app: ${ALL_CLUSTERS_APP}
50+
# test-runner-run/run1/factoryreset: True
51+
# test-runner-run/run1/quiet: True
52+
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
53+
# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
54+
4455
class TC_MYTEST_1_1(MatterBaseTest):
4556
4657
@async_test_body
@@ -74,6 +85,59 @@ The default_matter_test_main() function is used to run the test on the command
7485
line. These two lines should appear verbatim at the bottom of every python test
7586
file.
7687

88+
## Defining the test arguments
89+
90+
Below is the format:
91+
92+
```
93+
# test-runner-runs: <run_identifier>
94+
# test-runner-run/<run_identifier>/app: ${TYPE_OF_APP}
95+
# test-runner-run/<run_identifier>/factoryreset: <True|False>
96+
# test-runner-run/<run_identifier>/quiet: <True|False>
97+
# test-runner-run/<run_identifier>/app-args: <app_arguments>
98+
# test-runner-run/<run_identifier>/script-args: <script_arguments>
99+
```
100+
101+
### Description of Parameters
102+
103+
- test-runner-runs: Specifies the identifier for the run. This can be any
104+
unique identifier.
105+
106+
- Example: run1
107+
108+
- test-runner-run/<run_identifier>/app: Indicates the application to be used
109+
in the test. Different app types as needed could be referenced from section
110+
[name: Generate an argument environment file ] of the file
111+
[.github/workflows/tests.yaml](https://github.com/project-chip/connectedhomeip/blob/master/.github/workflows/tests.yaml)
112+
113+
- Example: \${TYPE_OF_APP}
114+
115+
- test-runner-run/<run_identifier>/factoryreset: Determines whether a factory
116+
reset should be performed before the test.
117+
118+
- Example: True
119+
120+
- test-runner-run/<run_identifier>/quiet: Sets the verbosity level of the test
121+
run. When set to True, the test run will be quieter.
122+
123+
- Example: True
124+
125+
- test-runner-run/<run_identifier>/app-args: Specifies the arguments to be
126+
passed to the application during the test.
127+
128+
- Example: --discriminator 1234 --KVS kvs1 --trace-to
129+
json:\${TRACE_APP}.json
130+
131+
- test-runner-run/<run_identifier>/script-args: Specifies the arguments to be
132+
passed to the test script.
133+
- Example: --storage-path admin_storage.json --commissioning-method
134+
on-network --discriminator 1234 --passcode 20202021 --trace-to
135+
json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
136+
137+
This structured format ensures that all necessary configurations are clearly
138+
defined and easily understood, allowing for consistent and reliable test
139+
execution.
140+
77141
## Cluster Codegen
78142

79143
- [Objects.py](https://github.com/project-chip/connectedhomeip/blob/master/src/controller/python/chip/clusters/Objects.py)

scripts/tests/run_python_test.py

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ def main(app: str, factoryreset: bool, factoryreset_app_only: bool, app_args: st
110110
)
111111
]
112112

113+
if not runs:
114+
raise Exception(
115+
"No valid runs were found. Make sure you add runs to your file, see https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md document for reference/example.")
116+
113117
for run in runs:
114118
print(f"Executing {run.py_script_path.split('/')[-1]} {run.run}")
115119
main_impl(run.app, run.factoryreset, run.factoryreset_app_only, run.app_args,

src/python_testing/hello_test.py

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
# limitations under the License.
1616
#
1717

18+
# test-runner-runs: run1
19+
# test-runner-run/run1/app: ${TYPE_OF_APP}
20+
# test-runner-run/run1/factoryreset: True
21+
# test-runner-run/run1/quiet: True
22+
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
23+
# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
24+
1825
import logging
1926

2027
import chip.clusters as Clusters

0 commit comments

Comments
 (0)