|
19 | 19 |
|
20 | 20 |
|
21 | 21 | class TestContextManager: |
| 22 | + def test_link_run_to_report(self, report_context, nostromo_run): |
| 23 | + report_context.report.update({"run_id": nostromo_run.id_}) |
| 24 | + assert report_context.report.run_id == nostromo_run.id_ |
| 25 | + |
22 | 26 | def test_new_step(self, report_context): |
23 | 27 | initial_end_time = report_context.report.end_time |
24 | 28 | first_step_path = report_context.get_next_step_path() |
@@ -124,41 +128,62 @@ def test_measurement_update(self, report_context): |
124 | 128 | assert test_step.measurements[2].measurement_type == TestMeasurementType.BOOLEAN |
125 | 129 |
|
126 | 130 | def test_bad_assert(self, report_context, step): |
127 | | - test_step = None |
128 | | - parent_step_path = step.current_step.step_path |
129 | | - initial_open_step_result = report_context.open_step_results.get(parent_step_path, True) |
| 131 | + # Capture current state of report context's failures so we can keep things passed at a high level if the test's induced failures happen as expected. |
| 132 | + current_step_path = step.current_step.step_path |
| 133 | + initial_open_step_result = report_context.open_step_results.get(current_step_path, True) |
130 | 134 | initial_any_failures = report_context.any_failures |
131 | 135 |
|
132 | | - with step.substep("Test Bad Assert", "Test Bad Assert Description") as new_step: |
133 | | - test_step = new_step.current_step |
134 | | - assert False == True |
135 | | - |
136 | | - assert test_step.status == TestStatus.ERROR |
137 | | - assert test_step.error_info is not None |
138 | | - assert "AssertionError" in test_step.error_info.error_message |
| 136 | + parent_step = None |
| 137 | + substep = None |
| 138 | + nested_substep = None |
| 139 | + sibling_substep = None |
| 140 | + with step.substep("Top Level Step", "Should fail") as parent_step_context: |
| 141 | + parent_step = parent_step_context.current_step |
| 142 | + with parent_step_context.substep("Parent Step", "Should fail") as substep_context: |
| 143 | + substep = substep_context.current_step |
| 144 | + with substep_context.substep( |
| 145 | + "Nested Substep", "Has a bad assert" |
| 146 | + ) as nested_substep_context: |
| 147 | + nested_substep = nested_substep_context.current_step |
| 148 | + assert False == True |
| 149 | + with substep_context.substep( |
| 150 | + "Sibling Substep", "Should pass" |
| 151 | + ) as sibling_substep_context: |
| 152 | + sibling_substep = sibling_substep_context.current_step |
| 153 | + |
| 154 | + assert parent_step.status == TestStatus.FAILED |
| 155 | + assert substep.status == TestStatus.FAILED |
| 156 | + assert nested_substep.status == TestStatus.ERROR |
| 157 | + assert "AssertionError" in nested_substep.error_info.error_message |
| 158 | + assert sibling_substep.status == TestStatus.PASSED |
| 159 | + |
| 160 | + # If this test was successful, mark that at a high level. |
139 | 161 | if initial_open_step_result: |
140 | | - report_context.open_step_results[parent_step_path] = True |
| 162 | + report_context.open_step_results[current_step_path] = True |
141 | 163 | if not initial_any_failures: |
142 | 164 | report_context.any_failures = False |
143 | 165 |
|
144 | | - def test_error_info(self, report_context, step): |
| 166 | + def test_manually_skip_step(self, step): |
145 | 167 | test_step = None |
146 | | - parent_step_path = step.current_step.step_path |
147 | | - initial_open_step_result = report_context.open_step_results.get(parent_step_path, True) |
148 | | - initial_any_failures = report_context.any_failures |
| 168 | + substep = None |
| 169 | + sibling_substep = None |
| 170 | + with step.substep("Parent Step", "Should pass") as parent_step_context: |
| 171 | + test_step = parent_step_context.current_step |
| 172 | + with parent_step_context.substep("Substep", "Should skip") as substep_context: |
| 173 | + substep = substep_context.current_step |
| 174 | + substep.update({"status": TestStatus.SKIPPED}) |
| 175 | + with substep_context.substep( |
| 176 | + "Sibling Substep", "Should pass" |
| 177 | + ) as sibling_substep_context: |
| 178 | + sibling_substep = sibling_substep_context.current_step |
149 | 179 |
|
150 | | - with report_context.new_step("Test Error", "Test Error Description") as new_step: |
151 | | - test_step = new_step.current_step |
152 | | - raise Exception("Test Error") |
153 | | - assert test_step.error_info is not None |
154 | | - assert test_step.error_info.error_code == 1 |
155 | | - assert "Test Error" in test_step.error_info.error_message |
156 | | - assert test_step.status == TestStatus.ERROR |
157 | | - # If the parent step is not marked as failed already, make sure it remains passed at this point. |
158 | | - if initial_open_step_result: |
159 | | - report_context.open_step_results[parent_step_path] = True |
160 | | - if not initial_any_failures: |
161 | | - report_context.any_failures = False |
| 180 | + assert test_step.status == TestStatus.PASSED |
| 181 | + assert substep.status == TestStatus.SKIPPED |
| 182 | + assert sibling_substep.status == TestStatus.PASSED |
| 183 | + |
| 184 | + @pytest.mark.skip(reason="Test Skip Step") |
| 185 | + def test_pytest_skip(self): |
| 186 | + pass |
162 | 187 |
|
163 | 188 |
|
164 | 189 | class TestBounds: |
|
0 commit comments