File tree Expand file tree Collapse file tree 4 files changed +41
-4
lines changed Expand file tree Collapse file tree 4 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 4
4
hooks :
5
5
- id : black
6
6
language_version : python3
7
- args : ["software/"]
8
7
- repo : https://github.com/pre-commit/pre-commit-hooks
9
8
rev : v4.5.0
10
9
hooks :
19
18
hooks :
20
19
- id : pytest
21
20
name : pytest
22
- entry : pytest software/tests
21
+ entry : python run_pytest.py
23
22
language : system
24
23
types : [python]
25
24
pass_filenames : false
Original file line number Diff line number Diff line change @@ -59,10 +59,12 @@ Our project uses `black` for code formatting and `isort` for import sorting. To
59
59
60
60
1 . ** Install Pre-commit Hooks** :
61
61
62
- If you want to automatically format your code every time you make a commit, install the pre-commit hooks.
62
+ To automatically format your code every time you make a commit, install the pre-commit hooks.
63
63
64
64
``` bash
65
- pip install pre-commit
65
+ cd software # Change into `software` directory if not there already.
66
+ poetry shell # It's better to do it within the virtual environment of your project
67
+ poetry add --dev pre-commit # Install pre-commit as a dev dependency
66
68
pre-commit install
67
69
```
68
70
Original file line number Diff line number Diff line change
1
+ import subprocess
2
+ import sys
3
+ import ctypes
4
+ import os
5
+
6
+
7
+ def main ():
8
+ """Run pytest in the software directory.
9
+
10
+ This script is intended to be used as a pre-commit hook to run the tests from the root of the repository.
11
+ """
12
+
13
+ # Additional setup for Windows (10 at least) to prevent issues with Unicode characters in the console.
14
+ # see https://www.reddit.com/r/learnpython/comments/350c8c/unicode_python_3_and_the_windows_console/
15
+ if sys .platform .startswith ("win" ):
16
+ # Force UTF-8 encoding in Python
17
+ os .environ ["PYTHONUTF8" ] = "1"
18
+
19
+ # Change Windows console code page to UTF-8
20
+ ctypes .windll .kernel32 .SetConsoleCP (65001 )
21
+ ctypes .windll .kernel32 .SetConsoleOutputCP (65001 )
22
+
23
+ # Define the target directory relative to this script location.
24
+ target_directory = os .path .join (os .path .dirname (__file__ ), "software" )
25
+
26
+ os .chdir (target_directory )
27
+
28
+ # Run pytest with any additional arguments passed to this script.
29
+ result = subprocess .run (["pytest" ] + sys .argv [1 :])
30
+
31
+ # Exit with pytest's exit code to reflect the test outcome in the pre-commit hook.
32
+ sys .exit (result .returncode )
33
+
34
+
35
+ if __name__ == "__main__" :
36
+ main ()
You can’t perform that action at this time.
0 commit comments