Skip to content

Find test resources relative to the test file, not the working directory - #1292

Merged
jhnwu3 merged 1 commit into
sunlabuiuc:masterfrom
solarsys:fix/test-resource-paths
Oct 14, 2026
Merged

jhnwu3 merged 1 commit into
sunlabuiuc:masterfrom
solarsys:fix/test-resource-paths

Conversation

@solarsys

Copy link
Copy Markdown
Collaborator

Problem

Two tests read their data file relative to the current directory:

  • tests/core/test_sdoh.py: pd.read_csv('test-resources/core/sdoh-test-cases.csv')
  • tests/nlp/test_metrics.py: Path('test-resources/nlp/metrics.csv')

They pass in CI, which runs from the repo root, but fail with FileNotFoundError when the suite is run from anywhere else. That includes running one module from tests/ (cd tests && python -m unittest core.test_sdoh). In the full core suite run that way, test_sdoh was the only error, which made real failures easier to miss.

Fix

Resolve both paths from __file__ (Path(__file__).parents[2] / "test-resources" / ...), as the other tests already do. These were the only two cwd-relative resource paths under tests/.

Tests

Both modules pass when run from the repo root, from tests/ and from an unrelated directory (/tmp). Before, the run from tests/ failed. Test-only change; tools/check_pr_rules.py passes.

🤖 Generated with Claude Code

test_sdoh and nlp/test_metrics read test-resources/... relative to the current
directory, so they failed whenever the suite was run from anywhere but the
repo root (for example the documented 'cd tests && python -m unittest core.x').
Resolve the paths from __file__, as the other tests already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@jhnwu3 jhnwu3 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jhnwu3
jhnwu3 merged commit 41d3679 into sunlabuiuc:master Oct 14, 2026
2 checks passed
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 participants