chore: optimise unit tests (#2293)

* optimise unit tests - Cache loading the config TOML

Unit test time: 13.1s -> 10.5s

* optimise unit tests - use the same pyproject validator across the tests

Unit test time: 10.5s -> 5.7s

* optimise unit tests - selector optimisation

Unit test time: 5.7s -> 5.1s

* optimise unit tests - build options computation cache

Unit test time: 5.1s -> 3.2s

* Use functools.cache rather than functools.lru_cache

* Don't overwrite build_options when applying functools.cache
This commit is contained in:
Joe Rickerby
2025-03-10 21:29:07 +01:00
committed by GitHub
parent bddd438a88
commit c136aefe20
4 changed files with 38 additions and 31 deletions
+8 -2
View File
@@ -591,6 +591,10 @@ class Options:
except FileNotFoundError:
self.pyproject_toml = None
# cache the build options method so repeated calls don't need to
# resolve the options again
self.build_options = functools.cache(self._compute_build_options)
@functools.cached_property
def config_file_path(self) -> Path | None:
args = self.command_line_arguments
@@ -667,9 +671,11 @@ class Options:
allow_empty=allow_empty,
)
def build_options(self, identifier: str | None) -> BuildOptions:
def _compute_build_options(self, identifier: str | None) -> BuildOptions:
"""
Compute BuildOptions for a single run configuration.
Compute BuildOptions for a single run configuration. Normally accessed
through the `build_options` method, which is the same but the result
is cached.
"""
with self.reader.identifier(identifier):