Skip to content

Commit 54f4011

Browse files
authored
Merge pull request #1272 from Flowminder/fm-tests
More useful test output for flowmachine tests, more durations
2 parents 81243eb + d1b42c4 commit 54f4011

File tree

3 files changed

+5
-51
lines changed

3 files changed

+5
-51
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ jobs:
414414
--cov flowmachine/ \
415415
--cov-report xml \
416416
--cov-report term \
417-
--durations=10
417+
--durations=50
418418
- store_test_results:
419419
path: test_results
420420
- run:

flowdb/tests/conftest.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,15 @@ def pytest_configure(config):
2727
)
2828

2929

30-
def get_string_with_test_parameter_values(item):
31-
"""
32-
If `item` corresponds to a parametrized pytest test, return a string
33-
containing the parameter values. Otherwise return an empty string.
34-
"""
35-
if "parametrize" in item.keywords:
36-
m = re.search(
37-
"(\[[^\]]*\])$", item.name
38-
) # retrieve text in square brackets at the end of the item's name
39-
if m:
40-
param_values_str = f" {m.group(1)}"
41-
else:
42-
warnings.warn(
43-
f"Test is parametrized but could not extract parameter values from name: '{item.name}'"
44-
)
45-
else:
46-
param_values_str = ""
47-
48-
return param_values_str
49-
50-
5130
def pytest_itemcollected(item):
5231
"""
5332
Custom hook which improves stdout logging from from pytest's default.
5433
5534
Instead of just printing the filename and no description of the test
56-
(as would be the default) it prints the docstring as the description
57-
and also adds info about any parameters (if the test is parametrized).
35+
(as would be the default) it also prints the docstring.
5836
"""
5937
if item.obj.__doc__:
60-
item._nodeid = "* " + " ".join(item.obj.__doc__.split())
61-
item._nodeid += get_string_with_test_parameter_values(item)
38+
item._nodeid = f'{item._nodeid} ({" ".join(item.obj.__doc__.split())})'
6239

6340

6441
class DBConn:

flowmachine/tests/conftest.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,38 +68,15 @@ def exemplar_spatial_unit_param(request):
6868
yield make_spatial_unit(**request.param)
6969

7070

71-
def get_string_with_test_parameter_values(item):
72-
"""
73-
If `item` corresponds to a parametrized pytest test, return a string
74-
containing the parameter values. Otherwise return an empty string.
75-
"""
76-
if "parametrize" in item.keywords:
77-
m = re.search(
78-
"(\[.*\])$", item.name
79-
) # retrieve text in square brackets at the end of the item's name
80-
if m:
81-
param_values_str = f" {m.group(1)}"
82-
else:
83-
raise RuntimeError(
84-
f"Test is parametrized but could not extract parameter values from name: '{item.name}'"
85-
)
86-
else:
87-
param_values_str = ""
88-
89-
return param_values_str
90-
91-
9271
def pytest_itemcollected(item):
9372
"""
9473
Custom hook which improves stdout logging from from pytest's default.
9574
9675
Instead of just printing the filename and no description of the test
97-
(as would be the default) it prints the docstring as the description
98-
and also adds info about any parameters (if the test is parametrized).
76+
(as would be the default) it also prints the docstring.
9977
"""
10078
if item.obj.__doc__:
101-
item._nodeid = "* " + " ".join(item.obj.__doc__.split())
102-
item._nodeid += get_string_with_test_parameter_values(item)
79+
item._nodeid = f'{item._nodeid} ({" ".join(item.obj.__doc__.split())})'
10380

10481

10582
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)