Skip to content

Commit ed9d604

Browse files
committed
Let pytest only test on changed python design patterns
1 parent cbfd21b commit ed9d604

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

.github/workflows/lint_pr.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,36 @@ jobs:
9696
run: |
9797
echo "Running pytest discovery..."
9898
python -m pytest --collect-only -v
99-
echo "Running tests..."
100-
python -m pytest ./tests -v
101-
python -m pytest --doctest-modules ./patterns -v || true
99+
100+
# First run any test files that correspond to changed files
101+
echo "Running tests for changed files..."
102+
changed_files="${{ needs.check_changes.outputs.files }}"
103+
104+
# Extract module paths from changed files
105+
modules=()
106+
for file in $changed_files; do
107+
# Convert file path to module path (remove .py and replace / with .)
108+
if [[ $file == patterns/* ]]; then
109+
module_path=${file%.py}
110+
module_path=${module_path//\//.}
111+
modules+=("$module_path")
112+
fi
113+
done
114+
115+
# Run tests for each module
116+
for module in "${modules[@]}"; do
117+
echo "Testing module: $module"
118+
python -m pytest -xvs tests/ -k "$module" || true
119+
done
120+
121+
# Then run doctests on the changed files
122+
echo "Running doctests for changed files..."
123+
for file in $changed_files; do
124+
if [[ $file == *.py ]]; then
125+
echo "Running doctest for $file"
126+
python -m pytest --doctest-modules -v $file || true
127+
fi
128+
done
102129
103130
# Check Python version compatibility
104131
- name: Check Python version compatibility

0 commit comments

Comments
 (0)