Skip to content

fix: exclude setuptools.tests from wheel distribution#5214

Open
Bahtya wants to merge 1 commit intopypa:mainfrom
Bahtya:fix/exclude-tests-from-wheel
Open

fix: exclude setuptools.tests from wheel distribution#5214
Bahtya wants to merge 1 commit intopypa:mainfrom
Bahtya:fix/exclude-tests-from-wheel

Conversation

@Bahtya
Copy link
Copy Markdown

@Bahtya Bahtya commented Apr 8, 2026

Problem

Starting from some release between v69.0.2 and v81.0.0, setuptools includes its own test suite in the wheel distribution. This violates the packaging guide:

Wheels are meant to contain exactly what is to be installed

Root Cause

The exclude patterns in pyproject.toml:

exclude = [
    "*.tests",
    "*.tests.*",
]

These glob patterns match packages named like foo.tests but do not match setuptools/tests/ because that is a subpackage of setuptools, not a top-level package matching the *.tests pattern.

Solution

Add explicit entries for the actual test package:

exclude = [
    "*.tests",
    "*.tests.*",
    "setuptools.tests",
    "setuptools.tests.*",
]

Fixes #5212

The exclude patterns '*.tests' and '*.tests.*' match packages named
like 'foo.tests' but do not match 'setuptools/tests' because that
directory is a subpackage of setuptools, not a top-level package
matching the glob.

Add explicit 'setuptools.tests' and 'setuptools.tests.*' to the
exclude list so test files are not included in the wheel.

Fixes pypa#5212

Signed-off-by: bahtya <bahtyar153@qq.com>
@abravalheri
Copy link
Copy Markdown
Contributor

Hi @Bahtya, thank you very much for the contribution.

I believe that this change is not working as expected: the original glob pattern itself should be working fine, but there is a different problem that influences the behaviour (a complicated one, nevertheless, because half of the community wants it to behave in a way while the other half wants it to behave in a different way: #3260, #3340)

But, just for the sake of sanity checking, could you please add some tests that assert that the proposed changes work to achieve the expected results?

@Bahtya
Copy link
Copy Markdown
Author

Bahtya commented Apr 8, 2026

Thanks for the feedback! I see the linked issues about the glob exclude pattern complexities.

Looking at this more carefully: if *.tests and *.tests.* should already match setuptools/tests, then the problem might be elsewhere in how setuptools.packages.find processes the exclude patterns during wheel building.

I'll investigate the actual wheel contents to understand what's happening. Could you point me to where in the build pipeline the exclude patterns are applied? Is the issue perhaps that setuptools/tests is being included because it's not matching the *.tests glob as a sub-package path?

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.

[BUG] Tests included in wheel distributions

2 participants