Skip to content

Commit 02ce034

Browse files
authored
Merge branch 'main' into ast-deduplication
2 parents ff8215a + 45b42a4 commit 02ce034

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

codeflash-benchmark/codeflash_benchmark/plugin.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,54 @@
88

99
PYTEST_BENCHMARK_INSTALLED = importlib.util.find_spec("pytest_benchmark") is not None
1010

11+
benchmark_options = [
12+
("--benchmark-columns", "store", None, "Benchmark columns"),
13+
("--benchmark-group-by", "store", None, "Benchmark group by"),
14+
("--benchmark-name", "store", None, "Benchmark name pattern"),
15+
("--benchmark-sort", "store", None, "Benchmark sort column"),
16+
("--benchmark-json", "store", None, "Benchmark JSON output file"),
17+
("--benchmark-save", "store", None, "Benchmark save name"),
18+
("--benchmark-warmup", "store", None, "Benchmark warmup"),
19+
("--benchmark-warmup-iterations", "store", None, "Benchmark warmup iterations"),
20+
("--benchmark-min-time", "store", None, "Benchmark minimum time"),
21+
("--benchmark-max-time", "store", None, "Benchmark maximum time"),
22+
("--benchmark-min-rounds", "store", None, "Benchmark minimum rounds"),
23+
("--benchmark-timer", "store", None, "Benchmark timer"),
24+
("--benchmark-calibration-precision", "store", None, "Benchmark calibration precision"),
25+
("--benchmark-disable", "store_true", False, "Disable benchmarks"),
26+
("--benchmark-skip", "store_true", False, "Skip benchmarks"),
27+
("--benchmark-only", "store_true", False, "Only run benchmarks"),
28+
("--benchmark-verbose", "store_true", False, "Verbose benchmark output"),
29+
("--benchmark-histogram", "store", None, "Benchmark histogram"),
30+
("--benchmark-compare", "store", None, "Benchmark compare"),
31+
("--benchmark-compare-fail", "store", None, "Benchmark compare fail threshold"),
32+
]
33+
1134

1235
def pytest_configure(config: pytest.Config) -> None:
1336
"""Register the benchmark marker and disable conflicting plugins."""
1437
config.addinivalue_line("markers", "benchmark: mark test as a benchmark that should be run with codeflash tracing")
1538

16-
if config.getoption("--codeflash-trace") and PYTEST_BENCHMARK_INSTALLED:
17-
config.option.benchmark_disable = True
18-
config.pluginmanager.set_blocked("pytest_benchmark")
19-
config.pluginmanager.set_blocked("pytest-benchmark")
39+
if config.getoption("--codeflash-trace"):
40+
# When --codeflash-trace is used, ignore all benchmark options by resetting them to defaults
41+
for option, _, default, _ in benchmark_options:
42+
option_name = option.replace("--", "").replace("-", "_")
43+
if hasattr(config.option, option_name):
44+
setattr(config.option, option_name, default)
45+
46+
if PYTEST_BENCHMARK_INSTALLED:
47+
config.pluginmanager.set_blocked("pytest_benchmark")
48+
config.pluginmanager.set_blocked("pytest-benchmark")
2049

2150

2251
def pytest_addoption(parser: pytest.Parser) -> None:
2352
parser.addoption(
2453
"--codeflash-trace", action="store_true", default=False, help="Enable CodeFlash tracing for benchmarks"
2554
)
55+
# These options are ignored when --codeflash-trace is used
56+
for option, action, default, help_text in benchmark_options:
57+
help_suffix = " (ignored when --codeflash-trace is used)"
58+
parser.addoption(option, action=action, default=default, help=help_text + help_suffix)
2659

2760

2861
@pytest.fixture
@@ -37,7 +70,7 @@ def benchmark(request: pytest.FixtureRequest) -> object:
3770
# If pytest-benchmark is installed and --codeflash-trace is not enabled,
3871
# return the normal pytest-benchmark fixture
3972
if PYTEST_BENCHMARK_INSTALLED:
40-
from pytest_benchmark.fixture import BenchmarkFixture as BSF # noqa: N814
73+
from pytest_benchmark.fixture import BenchmarkFixture as BSF # pyright: ignore[reportMissingImports] # noqa: I001, N814
4174

4275
bs = getattr(config, "_benchmarksession", None)
4376
if bs and bs.skip:

codeflash-benchmark/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "codeflash-benchmark"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
description = "Pytest benchmarking plugin for codeflash.ai - automatic code performance optimization"
55
authors = [{ name = "CodeFlash Inc.", email = "[email protected]" }]
66
requires-python = ">=3.9"
@@ -25,8 +25,8 @@ Repository = "https://github.com/codeflash-ai/codeflash-benchmark"
2525
codeflash-benchmark = "codeflash_benchmark.plugin"
2626

2727
[build-system]
28-
requires = ["setuptools>=45", "wheel", "setuptools_scm"]
28+
requires = ["setuptools>=45", "wheel"]
2929
build-backend = "setuptools.build_meta"
3030

3131
[tool.setuptools]
32-
packages = ["codeflash_benchmark"]
32+
packages = ["codeflash_benchmark"]

codeflash/discovery/pytest_new_process_discovery.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def parse_pytest_collection_results(pytest_tests: list[Any]) -> list[dict[str, s
4141

4242
try:
4343
exitcode = pytest.main(
44-
[tests_root, "-p no:logging", "--collect-only", "-m", "not skip"], plugins=[PytestCollectionPlugin()]
44+
[tests_root, "-p no:logging", "--collect-only", "-m", "not skip", "-p", "no:codeflash-benchmark"],
45+
plugins=[PytestCollectionPlugin()],
4546
)
4647
except Exception as e:
4748
print(f"Failed to collect tests: {e!s}")

uv.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)