Skip to content

Commit

Permalink
Fix machine_info hooks.
Browse files Browse the repository at this point in the history
Resolves issue with `pytest_benchmark_update_machine_info`
hooks not being executed, as cached `machine_info` property is retrieved
(and cached) during benchmark plugin initialization *before*
user-defined `conftest.py` modules are loaded.

Convert machine info from cached property to explicit generation
function, and generate once per `handle_saving`/`handle_loading` call.
  • Loading branch information
asford authored and ionelmc committed Jun 6, 2018
1 parent bd27744 commit 1635017
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/pytest_benchmark/session.py
Expand Up @@ -9,7 +9,6 @@
from .table import TableResults
from .utils import NAME_FORMATTERS
from .utils import SecondsDecimal
from .utils import cached_property
from .utils import first_or_value
from .utils import get_machine_id
from .utils import load_storage
Expand Down Expand Up @@ -93,8 +92,7 @@ def __init__(self, config):

self.histogram = first_or_value(config.getoption("benchmark_histogram"), False)

@cached_property
def machine_info(self):
def get_machine_info(self):
obj = self.config.hook.pytest_benchmark_generate_machine_info(config=self.config)
self.config.hook.pytest_benchmark_update_machine_info(
config=self.config,
Expand Down Expand Up @@ -136,6 +134,7 @@ def handle_saving(self):
if not self.benchmarks:
self.logger.warn("BENCHMARK-U2", "Not saving anything, no benchmarks have been run!")
return
machine_info = self.get_machine_info()
commit_info = self.config.hook.pytest_benchmark_generate_commit_info(config=self.config)
self.config.hook.pytest_benchmark_update_commit_info(config=self.config, commit_info=commit_info)

Expand All @@ -144,7 +143,7 @@ def handle_saving(self):
config=self.config,
benchmarks=self.benchmarks,
include_data=True,
machine_info=self.machine_info,
machine_info=machine_info,
commit_info=commit_info,
)
self.config.hook.pytest_benchmark_update_json(
Expand All @@ -159,7 +158,7 @@ def handle_saving(self):
config=self.config,
benchmarks=self.benchmarks,
include_data=self.save_data,
machine_info=self.machine_info,
machine_info=machine_info,
commit_info=commit_info,
)
self.config.hook.pytest_benchmark_update_json(
Expand Down Expand Up @@ -187,11 +186,12 @@ def handle_loading(self):
code = "BENCHMARK-C1"
self.logger.warn(code, msg, fslocation=self.storage.location)

machine_info = self.get_machine_info()
for path, compared_benchmark in compared_benchmarks:
self.config.hook.pytest_benchmark_compare_machine_info(
config=self.config,
benchmarksession=self,
machine_info=self.machine_info,
machine_info=machine_info,
compared_benchmark=compared_benchmark,
)
compared_mapping[path] = dict(
Expand Down

0 comments on commit 1635017

Please sign in to comment.