Skip to content

Commit

Permalink
BUG: Fix running subcommands with hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Nov 13, 2024
1 parent c960199 commit e5d4b55
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyperf/_process_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def load_hooks(metadata):
import pyperf._hooks

hook_managers = pyperf._hooks.instantiate_selected_hooks(hook_names)
metadata["hooks"] = ", ".join(hook_managers.values())
metadata["hooks"] = ", ".join(hook_managers.keys())
else:
hook_managers = {}

Expand Down
12 changes: 12 additions & 0 deletions pyperf/tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,18 @@ def test_bench_command(self):
self.assertEqual(bench.get_metadata()['command'],
' '.join(map(shell_quote, args)))

def test_hook_command(self):
args = [sys.executable, '-c', 'pass']

runner = self.create_runner('-l1 -w0 -n1 --worker --hook _test_hook'.split())
with tests.capture_stdout():
bench = runner.bench_command('bench', args)

self.assertEqual(bench.get_metadata()['command'],
' '.join(map(shell_quote, args)))
self.assertEqual(bench.get_metadata()["hooks"],
"_test_hook")

def test_single_instance(self):
runner1 = self.create_runner([]) # noqa
with self.assertRaises(RuntimeError):
Expand Down

0 comments on commit e5d4b55

Please sign in to comment.