Skip to content

Commit aa50301

Browse files
authored
Merge pull request #54 from HaoZeke/fix/52-bound-setup-cache
fix: do not run bound class setup before setup_cache
2 parents 3538c94 + fb6013d commit aa50301

5 files changed

Lines changed: 47 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang
88

99
<!-- towncrier release notes start -->
1010

11+
## [0.3.1](https://github.com/airspeed-velocity/asv_runner/tree/0.3.1) - 15-08-2026
12+
13+
### Bug Fixes
14+
15+
- Class-level ``setup(self)`` no longer runs inside ``do_setup_cache``.
16+
Bound methods are not treated as parameter-free module hooks, so
17+
``setup_cache`` runs first again
18+
([#52](https://github.com/airspeed-velocity/asv_runner/issues/52)).
19+
20+
1121
## [0.3.0](https://github.com/airspeed-velocity/asv_runner/tree/0.3.0) - 04-08-2026
1222

1323
### Bug Fixes

asv_runner/benchmarks/_base.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,11 +646,15 @@ def _build_params(self):
646646
@staticmethod
647647
def _is_parameter_free_setup(setup):
648648
"""
649-
True if ``setup`` can be called with no positional arguments.
649+
True if ``setup`` is a module-level hook callable with no arguments.
650650
651-
Used so module-level ``setup(*args, **kwargs)`` runs before
652-
``setup_cache`` while class ``setup(self, n)`` waits for ``do_setup``.
651+
Module-level ``setup(*args, **kwargs)`` (pandas seed, asv#1592) runs
652+
before ``setup_cache``. Bound class ``setup(self)`` and
653+
``setup(self, n)`` wait for ``do_setup``: ``inspect.signature`` omits
654+
``self`` on bound methods, so ``bind()`` alone would mis-fire.
653655
"""
656+
if inspect.ismethod(setup):
657+
return False
654658
try:
655659
inspect.signature(setup).bind()
656660
except TypeError:

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
project = "asv_runner"
88
copyright = "2023--present, asv Developers"
99
author = "asv Developers"
10-
release = "0.3.0"
10+
release = "0.3.1"
1111

1212
# -- General configuration ---------------------------------------------------
1313
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

tbump.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
github_url = "https://github.com/airspeed-velocity/asv_runner/"
33

44
[version]
5-
current = "0.3.0"
5+
current = "0.3.1"
66

77
# Example of a semver regexp.
88
# Make sure this matches current_version before

tests/test_cache_skip_setup.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,34 @@ def track_fn(cache, n):
104104
self.assertTrue(Benchmark._is_parameter_free_setup(module_setup))
105105
self.assertFalse(Benchmark._is_parameter_free_setup(class_setup))
106106

107+
def test_bound_class_setup_does_not_run_in_do_setup_cache(self):
108+
# Discovery builds sources as [func, instance, module], so class
109+
# setup(self) is a bound method. signature().bind() then succeeds
110+
# because self is already bound (asv_runner#52).
111+
order = []
112+
113+
class Suite:
114+
def setup(self):
115+
order.append("class_setup")
116+
raise AssertionError("class setup must not run in do_setup_cache")
117+
118+
def setup_cache(self):
119+
order.append("setup_cache")
120+
return {"ok": True}
121+
122+
def track_x(self):
123+
return 1
124+
125+
inst = Suite()
126+
func = inst.track_x
127+
b = TrackBenchmark(
128+
"mod.Suite.track_x", func, [func, inst, sys.modules[__name__]]
129+
)
130+
out = b.do_setup_cache()
131+
self.assertEqual(out, {"ok": True})
132+
self.assertEqual(order, ["setup_cache"])
133+
self.assertFalse(Benchmark._is_parameter_free_setup(inst.setup))
134+
107135
def test_benchmark_decorator_attrs_and_unknown(self):
108136
@benchmark(pretty_name="Pretty", timeout=12.5, max_time=30.0)
109137
def track_fn():

0 commit comments

Comments
 (0)