Python: a test inside a package misses imports that resolve from its basedir
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python, typescript
Research direction
Start in src/repo/adapters/python.ts at resolvePythonGraph and the per-file fileRoots logic. Read the existing Python graph tests and add a case matching the issue’s services/api/tests package layout, where test_app.py imports sibling app. Done when changing services/api/app.py selects that test and the end-to-end analysis reports it as affected.
Written by the indexing model from the issue text.
Description
resolvePythonGraph (src/repo/adapters/python.ts, the fileRoots line in the per-file loop) adds a file's own directory to the import roots only when that directory has no __init__.py. pytest's default prepend import mode puts the file's basedir on sys.path: the first directory above the file's package. A test inside a package below the repository root can import modules beside that package, and DiffCI misses the edge.
pyproject.toml [tool.pytest.ini_options]
services/api/app.py def f(): return 1
services/api/tests/__init__.py
services/api/tests/test_app.py import app
python -m pytest services/api/tests/test_app.py passes (pytest 9.2).
Expected: a change to services/api/app.py selects services/api/tests/test_app.py.
Actual: no edge and no blocker (app is not first-party when seen from the root), so the change is selective with no tests:
resolvePythonGraph(
["services/api/app.py", "services/api/tests/__init__.py", "services/api/tests/test_app.py"],
{ "services/api/app.py": { imports: [] }, "services/api/tests/__init__.py": { imports: [] },
"services/api/tests/test_app.py": { imports: [["app", 0, []]] } },
{ pythonFiles: ["test_*.py"], testpaths: [], pythonpath: [] },
new Set(["services/api/tests/test_app.py"]),
); // { edges: [], blockers: [] }
End to end, ImpactAnalyzer returns fallbackRequired: false and no affected tests.
Fix: resolve against the basedir: the file's directory when it is not a package, otherwise the nearest ancestor without __init__.py.
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 4
- Avg merge
- 18h 41m
- Merged PRs (30d)
- 48
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DiffCI/core
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Planner: splitParts regex is quadratic on a quote followed by many backticks, so the fuzz test fails at randomPossibly taken @FredApps claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
Agent tools: changed_files lists only the new path of a renamed filePossibly taken @FredApps claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
adapter good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
adapter bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
Similar issues
-
agent-ready area: ui-server priority: p3 type: test
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
schlessera/brain-kit#4249 ·
Maintainers usually reply within 1 day
-
documentation tool triaged
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
can1357/oh-my-pi#19608 · 2 comments ·
Maintainers usually reply within 1 day
-
dependencies tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
bcgov/nr-waste-plus#1549 ·
Maintainers usually reply within 1 day
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
blixvip/solana-token-meta#17 ·
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
blixvip/solana-tx-parse#18 ·