@@ -17,31 +17,61 @@ deps =
1717 sh >= 2.0.2, <3
1818 click
1919commands =
20- python - << ' EOF'
21- import os, shutil, sys, glob
20+ python - <<EOF
21+ import os, shutil, sys
2222
23- # {posargs} contains file(s) or directory paths passed from your action.yml
2423args = sys.argv[1:]
24+ copied = []
25+
26+ def copy_file(src):
27+ " " " Copy a file into a pytest-discoverable name." " "
28+ base = os.path.basename(src)
29+ new = f" test_{base}"
30+ shutil.copy(src, new)
31+ copied.append(new)
32+ print(f" [tox] Copied: {src} → {new}" )
33+
34+ def walk_dir(path):
35+ " " " Recursively copy all .py files inside a directory." " "
36+ for root, _, files in os.walk(path):
37+ for f in files:
38+ if f.endswith(" .py" ):
39+ copy_file(os.path.join(root, f))
2540
2641if not args:
27- # No file or directory passed → rely on pytest auto-discovery
28- sys.exit(0)
42+ print(" [tox] No files or directories passed — using pytest auto-discovery." )
43+ else:
44+ for path in args:
45+ if os.path.isdir(path):
46+ print(f" [tox] Recursively scanning directory: {path}" )
47+ walk_dir(path)
48+ elif os.path.isfile(path):
49+ copy_file(path)
50+ else:
51+ print(f" [tox] Warning: {path} does not exist and will be ignored." )
2952
30- for path in args:
31- if os.path.isdir(path):
32- # Copy all .py files inside the directory
33- for file in glob.glob(os.path.join(path, " *.py" )):
34- new = " test_" + os.path.basename(file)
35- shutil.copy(file, new)
36- elif os.path.isfile(path):
37- # Copy a single file
38- new = " test_" + os.path.basename(path)
39- shutil.copy(path, new)
40- else:
41- print(f" Warning: {path} does not exist and will be ignored." )
53+ # Store copied filenames for cleanup
54+ with open(" .tox_copied_files" , " w" ) as f:
55+ for name in copied:
56+ f.write(name + " \n" )
4257EOF
58+
4359 pytest --cov --cov-report =term-missing {posargs}
4460
61+ python - <<EOF
62+ import os
63+
64+ # Cleanup temporary test_*.py files
65+ if os.path.exists(" .tox_copied_files" ):
66+ with open(" .tox_copied_files" ) as f:
67+ for line in f:
68+ name = line.strip()
69+ if os.path.exists(name):
70+ os.remove(name)
71+ print(f" [tox] Cleaned up: {name}" )
72+ os.remove(" .tox_copied_files" )
73+ EOF
74+
4575[testenv:lint]
4676skip_install = true
4777deps =
0 commit comments