Skip to content

fix: keep the tests package out of the wheel - #156

Open
0z5a wants to merge 1 commit into
google:masterfrom
0z5a:wheel-without-tests
Open

0z5a wants to merge 1 commit into
google:masterfrom
0z5a:wheel-without-tests

Conversation

@0z5a

@0z5a 0z5a commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

I started from #155 and checked it against the code.

c236a53 changed packages=['textfsm'] to packages=find_packages(). With no arguments, find_packages() also picks up tests/, since it has an __init__.py, so the 2.1.1 wheel installs a top-level tests package next to textfsm. A regular package wins over a namespace package of the same name wherever each one sits on sys.path. A project whose own tests/ has no __init__.py then can't import from it once textfsm 2.1.1 is installed.

This keeps find_packages() and limits it to textfsm and its subpackages, as the issue suggests.

How I found it

I followed the setup.py history from the issue to c236a53. Then I built wheels from v2.1.0, current master and this branch and listed their top-level entries. To check the import side, I installed the master wheel into a fresh venv and used it from a small project that has tests/foo.py and no tests/__init__.py.

Where this can show up in practice

  • A project keeps tests/ as a namespace package and imports helpers as from tests.helpers import .... A dependency update that pulls in textfsm 2.1.1 (netmiko does) breaks test collection with ModuleNotFoundError: No module named 'tests.helpers', with no change in the project itself. This is the case 2.1.1 wheel installs a top-level tests package into site-packages, shadowing users' own tests packages #155 reports.
  • Two installed distributions both ship a top-level tests package. They write into the same site-packages/tests/, and uninstalling one of them removes files the other one put there.

The second one is my estimate; I have not seen a field report.

What changes

setup.py only: find_packages() becomes find_packages(include=['textfsm', 'textfsm.*']). The sdist doesn't change. MANIFEST.in still adds tests/ and testdata/ to it, which is what packagers asked for in #50.

I left package_data={'textfsm': ['../testdata/*']} alone. It also puts a top-level testdata/ into site-packages, as the issue notes, but that was already the case in 2.1.0 and isn't part of this regression.

Testing

wheel built from top-level entries
v2.1.0 testdata/, textfsm/, textfsm-2.1.0.dist-info/
master (7e4ed59) testdata/, tests/, textfsm/, textfsm-2.1.1.dist-info/
this branch testdata/, textfsm/, textfsm-2.1.1.dist-info/

textfsm/ has the same five modules in all three.

With the master wheel installed, from tests.foo import bar in the small project fails with ModuleNotFoundError: No module named 'tests.foo', and import tests resolves to site-packages/tests/__init__.py. With the wheel from this branch the import works, and the installed textfsm --help still runs. pytest tests passes (113) on Python 3.9 and 3.11. The sdist from this branch still contains tests/, testdata/ and examples/.

If you check this locally, build from a clean tree: a build/lib/tests/ left over from an earlier build ends up in the wheel again.

I ran this on macOS only. I didn't run the publish workflow or upload to TestPyPI. I didn't add a test, since the repo has no packaging tests.

Fixes #155

find_packages() without arguments also finds tests/, so the 2.1.1
wheel installs a top-level `tests` package into site-packages. That
regular package shadows a project's own `tests` namespace package.

Limit find_packages() to textfsm and its subpackages. The sdist still
gets tests/ and testdata/ through MANIFEST.in.

Fixes google#155

This branch has not been deployed

No deployments
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.

2.1.1 wheel installs a top-level tests package into site-packages, shadowing users' own tests packages

1 participant