kubeflow / kubeflow/pipelines-components

[BUG] pytest breaks in git worktrees due to misconfigured repository

Open Beginner friendly
#181 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
12
Forks
56
Avg merge
1d 11h
Merged PRs (30d)
3

Description

## Description
Running pytest from a git worktree fails with `ModuleNotFoundError` because the root `__init__.py` causes pytest to derive the module name from the worktree directory name, which doesn't correspond to any installed Python package.

Pytest's default prepend import mode walks up from _conftest.py_ looking for the highest directory containing __init__.py. It finds the project root (which has __init__.py), then tries to import conftest.py as `.conftest`. Since the worktree directory name (e.g. my_feature_branch) is not a real Python module, the import fails.

## Steps to Reproduce

1. Create a git worktree: git worktree add ../my_feature_branch some-branch
2. cd ../my_feature_branch
3. Run pytest --collect-only

## Expected Behavior

pytest can be run in and out git worktrees

## Actual Behavior

pytest does not work in git worktrees

## Error Messages/Logs

```text
ImportError while loading conftest '.../my_feature_branch/conftest.py'.
ModuleNotFoundError: No module named 'my_feature_branch'
```

## Environment

- Kubeflow SDK Version: 2.16.0
- Python Version: 3.12.12

## Additional Context

The root cause is the combination of:

* Root __init__.py existing in the project root
* pyproject.toml mapping "kfp_components" = "."
* Pytest's default prepend import mode resolving module names from directory structure

This works on the main checkout but breaks in any worktree (and probably clone with a non-standard directory name).

## Possible Solution

Remove root directory `__init__.py`. The kfp_components package is already properly defined via the [tool.setuptools.package-dir] mapping in pyproject.toml, so import kfp_components works without a root __init__.py. The file currently just contains a docstring and serves no functional purpose beyond triggering this pytest bug in worktrees.

## Willing to Contribute

- [x] Yes, I can submit a fix
- [x] Yes, I can help with testing
- [x] Yes, I can help with documentation
- [ ] No, requesting community help

---

Impacted by this bug? Give it a 👍.

Contributor guide

Open the contributing guide

Research direction

Start with the root __init__.py and the package mapping in pyproject.toml, then review the root conftest.py import path described in the issue. Reproduce the failure with pytest --collect-only in a git worktree and verify that collection succeeds there and in the main checkout without the ModuleNotFoundError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system, testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.