Python 带pytest和版本控制的Exercism.io自动化
我是新来的。我目前正在为的python跟踪工作。我正在寻找一种方法来自动化从pytest运行测试的过程,提交并推送到github,最后在所有测试都通过时提交到exercism。我已经实现了一个预提交钩子来调用提交时的测试,但我不确定如何将文件名传递回exercism进行提交。非常感谢您的帮助 我为其他寻找类似工作流的人提供了一个解决方案。它利用根目录中的python脚本,并通过子流程处理git命令。它还支持文件目录的自动完成(基于)。此脚本假定您已经初始化了git repo并设置了远程repoPython 带pytest和版本控制的Exercism.io自动化,python,bash,git,continuous-integration,pytest,Python,Bash,Git,Continuous Integration,Pytest,我是新来的。我目前正在为的python跟踪工作。我正在寻找一种方法来自动化从pytest运行测试的过程,提交并推送到github,最后在所有测试都通过时提交到exercism。我已经实现了一个预提交钩子来调用提交时的测试,但我不确定如何将文件名传递回exercism进行提交。非常感谢您的帮助 我为其他寻找类似工作流的人提供了一个解决方案。它利用根目录中的python脚本,并通过子流程处理git命令。它还支持文件目录的自动完成(基于)。此脚本假定您已经初始化了git repo并设置了远程repo
#!/usr/bin/env python
import pytest
import subprocess
import readline
import glob
class tabCompleter(object):
"""
A tab completer that can complete filepaths from the filesystem.
Partially taken from:
http://stackoverflow.com/questions/5637124/tab-completion-in-pythons-raw-input
"""
def pathCompleter(self,text,state):
"""
This is the tab completer for systems paths.
Only tested on *nix systems
"""
return [x for x in glob.glob(text+'*')][state]
if __name__=="__main__":
# Take user input for commit message
commit_msg = raw_input('Enter the commit message: ')
t = tabCompleter()
readline.set_completer_delims('\t')
# Necessary for MacOS, Linux uses tab: complete syntax
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")
#Use the new pathCompleter
readline.set_completer(t.pathCompleter)
#Take user input for exercise file for submission
ans = raw_input("Select the file to submit to Exercism: ")
if pytest.main([]) == 0:
"""
If all tests pass:
add files to index,
commit locally,
submit to exercism.io,
then finally push to remote repo.
"""
subprocess.call(["git","add","."])
subprocess.call(["git","commit","-m", commit_msg])
subprocess.call(["exercism","submit",ans])
subprocess.call(["git","push","origin","master"])