Skip to content

fix: exclude setuptools.tests from wheel distribution#5214

Open
Bahtya wants to merge 2 commits intopypa:mainfrom
Bahtya:fix/exclude-tests-from-wheel
Open

fix: exclude setuptools.tests from wheel distribution#5214
Bahtya wants to merge 2 commits 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?

@Bahtya
Copy link
Copy Markdown
Author

Bahtya commented Apr 18, 2026

Hi @abravalheri, just checking if you had a chance to review my follow-up. I understand the glob exclude pattern concern — happy to adjust the approach if the current one doesn't meet the project's needs. Thanks!

@abravalheri
Copy link
Copy Markdown
Contributor

abravalheri commented Apr 18, 2026

Hi @Bahtya I suggest having a look on the issues I pointed out in my previous comment #5214 (comment).

I suggest start by adding the tests to make sure the changes achieve what you want to achieve... Then you can double check if the approach you are suggesting is appropriate or not.

…work

The existing exclude patterns `*.tests` and `*.tests.*` already correctly
exclude `setuptools.tests` and its subpackages via fnmatch glob matching.
The explicit `setuptools.tests` and `setuptools.tests.*` patterns were
redundant.

Add TestGlobExcludePatterns to verify the glob exclude patterns work as
expected, addressing the maintainer's review feedback.

Bahtya

Signed-off-by: Bahtya <bahtyar153@qq.com>
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