Skip to content

Commit 0eddbff

Browse files
committed
fix(pytest-profiling): crash when adding options to parser
`Crash: ValueError('%r is not callable' % (type_func,)) with 1.8.0`` Fixes man-group#242
1 parent 286e040 commit 0eddbff

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

pytest-profiling/pytest_profiling.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def pytest_addoption(parser):
143143
help="generate profiling graph (using gprof2dot and dot -Tsvg)")
144144
group.addoption("--pstats-dir", nargs=1,
145145
help="configure the dump directory of profile data files")
146-
group.addoption("--element-number", action="store", type="int", default=20,
146+
group.addoption("--element-number", action="store", type=int, default=20,
147147
help="defines how many elements will display in a result")
148148
group.addoption("--strip-dirs", action="store_true",
149149
help="configure to show/hide the leading path information from file names")

pytest-profiling/tests/unit/test_profile.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313
import subprocess
1414

15+
import pytest
1516
from pytest_profiling import Profiling, pytest_addoption, pytest_configure
1617

1718
try:
@@ -94,12 +95,19 @@ def test_writes_summary_svg():
9495

9596

9697
def test_adds_options():
97-
parser = Mock()
98+
parser = pytest.Parser()
9899
pytest_addoption(parser)
99-
parser.getgroup.assert_called_with("Profiling")
100-
group = parser.getgroup.return_value
101-
group.addoption.assert_any_call("--profile", action="store_true", help=ANY)
102-
group.addoption.assert_any_call("--profile-svg", action="store_true", help=ANY)
100+
group = parser.getgroup("Profiling")
101+
options = {
102+
option.dest: option for option in group.options
103+
}
104+
assert set(options.keys()) == {"profile", "profile_svg", "pstats_dir", "element_number", "strip_dirs"}
105+
assert options["profile"]._attrs["action"] == "store_true"
106+
assert options["profile_svg"]._attrs["action"] == "store_true"
107+
assert options["pstats_dir"]._attrs["nargs"] == 1
108+
assert options["strip_dirs"]._attrs["action"] == "store_true"
109+
assert options["element_number"]._attrs["action"] == "store"
110+
assert options["element_number"]._attrs["default"] == 20
103111

104112

105113
def test_configures():

0 commit comments

Comments
 (0)