-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pytest call from pre-commit hook
- Loading branch information
Showing
4 changed files
with
43 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import subprocess | ||
import sys | ||
import ctypes | ||
import os | ||
|
||
|
||
def main(): | ||
"""Run pytest in the software directory. | ||
This script is intended to be used as a pre-commit hook to run the tests from the root of the repository. | ||
""" | ||
|
||
# Additional setup for Windows (10 at least) to prevent issues with Unicode characters in the console. | ||
# see https://www.reddit.com/r/learnpython/comments/350c8c/unicode_python_3_and_the_windows_console/ | ||
if sys.platform.startswith("win"): | ||
# Force UTF-8 encoding in Python | ||
os.environ["PYTHONUTF8"] = "1" | ||
|
||
# Change Windows console code page to UTF-8 | ||
ctypes.windll.kernel32.SetConsoleCP(65001) | ||
ctypes.windll.kernel32.SetConsoleOutputCP(65001) | ||
|
||
# Define the target directory relative to this script location. | ||
target_directory = os.path.join(os.path.dirname(__file__), "software") | ||
|
||
os.chdir(target_directory) | ||
|
||
# Run pytest with any additional arguments passed to this script. | ||
result = subprocess.run(["pytest"] + sys.argv[1:]) | ||
|
||
# Exit with pytest's exit code to reflect the test outcome in the pre-commit hook. | ||
sys.exit(result.returncode) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Empty file.