Skip to content

fix(packaging): exclude tests from the wheel - #979

Merged
Abhijeet Prasad (AbhiPrasad) merged 5 commits into
mainfrom
abhi/remove-test-files-wheel-c963bfee
Oct 19, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 5 commits into
mainfrom
abhi/remove-test-files-wheel-c963bfee

Conversation

@AbhiPrasad

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

The wheel ships our colocated tests: 154 of its 465 files are test_*.py, conftest.py, private test helpers (_test_*.py), type_tests/ and fixtures/test-image.png. That puts a conftest.py into users' site-packages and roughly doubles the wheel size. Some shipped tests don't even work: one btx test module crashes on import because braintrust/btx/spec-ref.txt isn't packaged.

Changes

  • Exclude tests from the wheel. py/_build_hooks.py adds a build_py subclass that drops test_*, _test_* and conftest modules. It is registered via [tool.setuptools.cmdclass] with backend-path = ["."], and included in the sdist through MANIFEST.in because uv builds the wheel from the sdist. type_tests/ and fixtures/ are excluded both as packages and as package data. Pyproject settings alone can't do this, because exclude-package-data doesn't filter .py modules. The sdist still contains the tests.
    • Wheel: 465 → 307 files, 1.16 MB → 0.68 MB compressed.
    • braintrust.test_helpers is still shipped. It's public and downstream test suites import it (zenml-io/kitaru and braintrustdata/docs-training use with_memory_logger and init_test_logger). The smoke test checks that it stays importable.
  • Replace make test-wheel. It ran nox -s test_core -- --wheel, which executed the tests shipped inside the wheel. It now runs a new test_wheel session over py/tests/wheel/test_wheel.py, from a temp dir against the wheel in dist/. The test checks:
    • braintrust is imported from site-packages
    • the version is templated
    • py.typed is present
    • no test files, cassettes, type_tests/ or fixtures/ are in the wheel
    • every braintrust.* submodule imports, allowing missing optional third-party packages
    • the pytest11, console script and harbor entry points resolve
    • braintrust --help works
    • a local Eval(..., no_send_logs=True) runs
  • Remove the old --wheel mode: the noxfile plumbing, the wheel-only VCR skip in conftest.py, the wheel branch in test_version.py, and two dead "scripts/ not available" skips.
  • CI:
    • test_wheel is excluded from the sharded nox matrix (in checks.yaml and update-session-weights.yaml).
    • The upload-wheel job now runs build test-wheel, so packaging regressions like fix(packaging): include image fixture in wheel #977 fail on PRs instead of at release time.
    • Release workflows pick up the new check through verify-build unchanged.

Validation

  • make build && make test-wheel: 11 passed.
  • The same suite against a wheel built from current main fails test_does_not_ship_tests and test_all_modules_import (the btx spec-ref.txt crash). Its version check also failed, but only because that wheel was built without templating.
  • nox -s test_core from source: 1095 passed, 106 skipped, 12 xfailed.
  • pre-commit passes.

🤖 Generated with Claude Code

Colocated tests, test helpers, conftest.py, type_tests/ and test fixtures
were shipped in the wheel (154 of 465 files). A setuptools build_py hook
now drops them, shrinking the wheel from 1.16 MB to 0.68 MB.

`make test-wheel` previously ran the shipped tests from site-packages, so
it is replaced by a `test_wheel` nox session running py/tests/wheel/: a
smoke test that checks version templating, py.typed, absence of test
files, that every module imports, entry points, the CLI, and a local Eval.
The upload-wheel CI job now runs it so packaging regressions fail on PRs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T22:06:09.137821Z 0da5274 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 77ca3d32ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread py/noxfile.py Outdated
Comment on lines +832 to +833
@nox.session()
def test_wheel(session):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the wheel check out of default test runs

When a developer runs the documented make test target from a clean checkout, it invokes nox -x without selecting sessions, so this new default session runs without the required preceding make build; _get_braintrust_wheel() then raises because dist/ contains no wheel. Nox documents that all default sessions run when none are specified and that default=False removes an explicitly invoked session from that set (Nox configuration), so declare this build-dependent session with @nox.session(default=False) (or exclude it from make test).

AGENTS.md reference: AGENTS.md:L152-L152

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed in 87b6ef2: test_wheel is now @nox.session(default=False), so make test (bare nox -x) no longer picks it up. make test-wheel still selects it explicitly (verified: 11 passed after make build). Since nox -l lists non-default sessions with - rather than * , scripts/nox-matrix.py already skips it, so I also dropped the now-redundant --exclude-session test_wheel flags from checks.yaml and update-session-weights.yaml.

test_helpers is public and imported by downstream test suites (e.g.
zenml-io/kitaru, braintrustdata/docs-training) for with_memory_logger and
init_test_logger, so excluding it would break them. Keep shipping it and
assert it in the wheel smoke test. Also drop a stale wheel-mode note from
CONTRIBUTING.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`make test` runs a bare `nox -x`, which would pick up test_wheel and fail
without a built wheel in dist/. Mark it default=False; it still runs when
selected explicitly via `make test-wheel`. Non-default sessions are not
listed with `* ` by `nox -l`, so nox-matrix.py already skips it and the
explicit --exclude-session flags in CI are dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The upload-wheel job now runs `make test-wheel`; update the reproduction
steps and note how to read test_wheel failures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0da52743c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment thread py/pyproject.toml
[build-system]
requires = ["setuptools>=82.0.1"]
build-backend = "setuptools.build_meta"
backend-path = ["."]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the invalid setuptools backend path

Setting backend-path = ["."] declares that the PEP 517 backend itself must be loaded from this directory, but setuptools.build_meta is supplied by the build environment rather than the repository. Standards-compliant frontends therefore reject source and editable installs: for example, pip wheel . --no-build-isolation --no-deps now fails with BackendUnavailable: Cannot find module 'setuptools.build_meta' in ['.../py']. This breaks common pip install workflows from a checkout, Git URL, or sdist; expose the custom hook without declaring external setuptools as an in-tree backend.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in 9868792. Reproduced BackendUnavailable with pip wheel . both with and without build isolation (uv doesn't enforce the in-tree check, which is why make build passed). _build_hooks.py is now the in-tree backend: it re-exports setuptools.build_meta (setuptools' documented wrapper pattern) and build-backend = "_build_hooks". Verified: pip wheel . (isolated and --no-build-isolation) and pip wheel <sdist> all succeed with 307 files and no test modules; pip install -e . still resolves tests from src/; make build && make test-wheel passes; editable test_core subset passes.

`backend-path = ["."]` with `build-backend = "setuptools.build_meta"` is
rejected by pip (BackendUnavailable), because PEP 517 requires a backend
named with backend-path to live in that path, breaking pip installs from a
checkout, Git URL, or sdist. uv does not enforce this. Make _build_hooks the
backend by re-exporting setuptools.build_meta, per setuptools' documented
in-tree backend pattern.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit f844512 into main Oct 19, 2026
98 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the abhi/remove-test-files-wheel-c963bfee branch October 19, 2026 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant