Skip to content

Commit ebc1ece

Browse files
committed
feat: better test names
1 parent 69a631c commit ebc1ece

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

SchemathesisLibrary/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@ def get_data_from_source(
4444
all_cases = []
4545
for op in schema.get_all_operations():
4646
op_as_strategy = op.ok().as_strategy() # type: ignore
47-
for case in generate_examples(op_as_strategy, 10):
47+
for case in generate_examples(op_as_strategy, 5):
4848
args = {
4949
"${case}": case,
5050
}
51-
all_cases.append(TestCaseData(test_case_name=str(case.id), arguments=args))
51+
path_params = case.path_parameters if case.path_parameters else ""
52+
all_cases.append(
53+
TestCaseData(
54+
test_case_name=f"{case.method} {case.full_path} {path_params}", arguments=args
55+
)
56+
)
5257
return all_cases
5358

5459

tasks.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from collections import defaultdict
1415
from pathlib import Path
1516
import time
1617

1718
import requests
1819
from invoke.tasks import task
1920
from robot.libdoc import libdoc
21+
from robot.api import ExecutionResult, ResultVisitor
22+
from robot.result.model import TestCase
2023

2124
ROOT_DIR = Path(__file__).parent
2225
ATEST_OUTPUT_DIR = ROOT_DIR / "atest" / "output"
@@ -92,6 +95,39 @@ def docs(ctx, version: str | None = None):
9295
output.rename(target)
9396

9497

98+
class ExecutionTimeChecker(ResultVisitor):
99+
def __init__(self, names: dict[str, int]):
100+
self.names = names
101+
self.visited_names = defaultdict(int)
102+
103+
def visit_test(self, test: TestCase):
104+
if name := self._test_found(test):
105+
self.visited_names[name] += 1
106+
if self.visited_names[name] > self.names[name]:
107+
test.status = "FAIL"
108+
else:
109+
test.status = "FAIL"
110+
111+
def _test_found(self, test: TestCase):
112+
for name in self.names:
113+
if name in test.name:
114+
return name
115+
return False
116+
117+
118+
119+
def check_tests(output_xml):
120+
result = ExecutionResult(output_xml)
121+
test = {
122+
"DELETE /": 5,
123+
"PUT /": 5,
124+
"GET / ": 1,
125+
"GET /items/{item_id}": 5,
126+
}
127+
result.visit(ExecutionTimeChecker(test))
128+
result.save(output_xml)
129+
130+
95131
@task(pre=[test_app])
96132
def atest(ctx):
97133
"""Run acceptance tests."""
@@ -105,7 +141,26 @@ def atest(ctx):
105141
".",
106142
"--outputdir",
107143
ATEST_OUTPUT_DIR.as_posix(),
144+
"--log",
145+
"NONE",
146+
"--report",
147+
"NONE",
108148
"atest/test",
109149
]
110150
ATEST_OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
111151
ctx.run(" ".join(args))
152+
output_xml = ATEST_OUTPUT_DIR / "output.xml"
153+
check_tests(output_xml.as_posix())
154+
log_file = ATEST_OUTPUT_DIR / "log.html"
155+
report_file = ATEST_OUTPUT_DIR / "report.html"
156+
rebot_args = [
157+
"uv",
158+
"run",
159+
"rebot",
160+
"--log",
161+
log_file.as_posix(),
162+
"--report",
163+
report_file.as_posix(),
164+
output_xml.as_posix(),
165+
]
166+
ctx.run(" ".join(rebot_args))

0 commit comments

Comments
 (0)