A project under a directory named test, tests or spec is skipped entirely

Open Beginner friendly
#56 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
tooling

Research direction

Start with is_test_file in src/crapper/discover.py and trace how iter_source_files and the CLI resolve paths; compare the project-relative test-directory handling described for mutator. Reproduce with a project beneath a directory named test, then verify source files are analyzed and an empty run does not silently pass. Check whether dryer shares the same behavior.

Written by the indexing model from the issue text.

Description

is_test_file (src/crapper/discover.py) looks at every part of the path, and the paths it gets are absolute, because iter_source_files and the CLI resolve them. When any directory above the project root is named test, tests, spec, specs or __tests__, every source file counts as a test. crapper then prints No source files to analyze., exits 0, and writes no .metrics/crap.edn.

mkdir -p /tmp/test/demo/src/demo /tmp/work/demo/src/demo
printf 'def sign(x):\n    if x > 0:\n        return 1\n    return 0\n' | tee /tmp/test/demo/src/demo/core.py > /tmp/work/demo/src/demo/core.py
(cd /tmp/work/demo && crapper --no-coverage)   # sign  demo.core  2  N/A  N/A
(cd /tmp/test/demo && crapper --no-coverage)   # No source files to analyze.  exit 0

mutator handles the same rule correctly: it skips a test directory only when that directory is the first component of the path relative to the project root. crapper could check path.relative_to(root).parts in the same way.

Because the run exits 0, a quality gate built on crapper passes without checking anything. An empty run could exit non-zero.

dryer has the same is_test_file and behaves the same way (No source files to analyze., exit 0).

Dominant language
Python
Stars
255
Forks
101
Avg merge
7m
Merged PRs (30d)
4

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from unclebob/crapper

All issues in unclebob/crapper

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.