cache_invalidation_files with `**` doesn't catch files at the top of the directory

Đang mở Phù hợp với người mới
#627 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
74/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
testing

Hướng nghiên cứu

Bắt đầu bằng cách lần theo cách cache_invalidation_files được mở rộng thành watched_file_hashes và cách _changed_hashed_files(restrict_to=...) lọc các đường dẫn đó; so sánh hai hành vi khớp được mô tả trong issue. Tái hiện bằng các tệp ở cấp cao nhất và trong thư mục lồng nhau dưới tests, sau đó kiểm tra rằng cả hai đều kích hoạt chạy lại với mẫu đệ quy. Issue không nêu tên tệp kiểm thử, vì vậy hãy tìm hoặc thêm một kiểm thử hồi quy tập trung cho cả hai đường dẫn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

mutmut 3.8.0 (the same matching code is still on master)

I tried this as a workaround for #626:

cache_invalidation_files = ["tests/**/*.py"]
on_dependency_change = "rerun"

It works for tests/sub/test_deep.py:

    1 non-Python file(s) changed; rerunning all mutants: tests/sub/test_deep.py
    calc.ops.x_is_adult__mutmut_1: survived
    calc.ops.x_is_adult__mutmut_2: survived

but not for tests/test_ops.py. With the script from #626 (bash repro.sh watch) the warm run
still says killed and doesn't print the "rerunning" line.

The baseline is built with Path(".").glob("tests/**/*.py"), where ** can match zero
directories, so tests/test_ops.py does end up in watched_file_hashes. But
_changed_hashed_files(restrict_to=cfg.cache_invalidation_files) then filters with
fnmatch, and for fnmatch **/ needs a literal slash:

>>> from fnmatch import fnmatch
>>> fnmatch("tests/test_ops.py", "tests/**/*.py")
False
>>> fnmatch("tests/a/b.py", "tests/**/*.py")
True

So the file is dropped, and _changed_hashed_files() returns an empty set even though the hash
changed. A top-level tests/conftest.py would never trigger a rerun either.

"tests/*.py" on its own has the opposite problem: the top-level file is caught, but the glob
doesn't recurse, so files in sub-directories never get into the baseline. Listing both works:

tests/**/*.py               top-level: missed   tests/sub/: caught
tests/*.py                  top-level: caught   tests/sub/: missed
tests/*.py + tests/**/*.py  top-level: caught   tests/sub/: caught

(checked each combination against a weakened test at both locations)

A fix could be to use the same matching in both places, e.g. PurePath.full_match() on 3.13+,
or check membership in the paths the glob returned.

Ngôn ngữ chính
Python
Star
1.5k
Fork
191
Merge trung bình
1 ngày 7 giờ
Pull request đã merge (30 ngày)
9

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của boxed/mutmut

Tất cả issue của boxed/mutmut

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.