2013-10-22 24 views
0

我使用pytest運行PEP8檢查(所有下面列出的是發生在Windows機器上的):違規插件使用錯誤的路徑來尋找PEP8報告

py.test --pep8 --junitxml=reports\pep8.log 

我的設置工作,尋找PEP8在報告.log文件\ pep8.log

但是當我運行我看到那裏的侵犯插件查找報告的路徑是沒有意義的工作:

generated xml file: C:\Jenkins\jobs\python-template-2\workspace\reports\pep8.log =============== 89 failed, 33 skipped, 1 error in 1.48 seconds ================

C:\Jenkins\jobs\python-template-2\workspace>exit 1 Build step 'Выполнить команду Windows' marked build as failure ERROR: Publisher hudson.plugins.violations.ViolationsPublisher aborted due to exception java.io.FileNotFoundException: C:\Jenkins\jobs\python-template-2\builds\2013-10-22_13-30-44\violations\file\<\failure><\testcase>C:\Jenkins\jobs\python-template-2\workspace\contests\migrations\0003_auto__add_votinghistory.py.xml (Syntax error in filename) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.(Unknown Source) at java.io.FileOutputStream.(Unknown Source) at hudson.FilePath.write(FilePath.java:1642) at hudson.plugins.violations.generate.ExecuteFilePath.execute(ExecuteFilePath.java:40) at hudson.plugins.violations.generate.GenerateXML.execute(GenerateXML.java:47) at hudson.plugins.violations.ViolationsCollector.invoke(ViolationsCollector.java:122) at hudson.plugins.violations.ViolationsCollector.invoke(ViolationsCollector.java:25) at hudson.FilePath.act(FilePath.java:912) at hudson.FilePath.act(FilePath.java:885) at hudson.plugins.violations.ViolationsPublisher.perform(ViolationsPublisher.java:74) at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:781) at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:753) at hudson.model.Build$BuildExecution.post2(Build.java:183) at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:706) at hudson.model.Run.execute(Run.java:1690) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:230) Finished: FAILURE

Addittionally,嘗試啓動PEP8檢查無使用pyt EST,而不是我用這個命令窗口,找到並檢查所有.py文件:

FOR /R %i IN (*.py) DO pep8 %i 1>>reports\pep8.log 

在這種情況下,我得到如下:

C:\Jenkins\jobs\python-template-2\workspace>exit 1 Build step 'Выполнить команду Windows' marked build as failure ERROR: Publisher hudson.plugins.violations.ViolationsPublisher aborted due to exception java.io.FileNotFoundException: C:\Jenkins\jobs\python-template-2\builds\2013-10-15_13-31-37\violations\file\C:\Jenkins\jobs\python-template-2\workspace\notifications\email.py.xml (Syntax error in filename) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.(Unknown Source) at java.io.FileOutputStream.(Unknown Source) at hudson.FilePath.write(FilePath.java:1666) at hudson.plugins.violations.generate.ExecuteFilePath.execute(ExecuteFilePath.java:40) at hudson.plugins.violations.generate.GenerateXML.execute(GenerateXML.java:47) at hudson.plugins.violations.ViolationsCollector.invoke(ViolationsCollector.java:122) at hudson.plugins.violations.ViolationsCollector.invoke(ViolationsCollector.java:25) at hudson.FilePath.act(FilePath.java:916) at hudson.FilePath.act(FilePath.java:889) at hudson.plugins.violations.ViolationsPublisher.perform(ViolationsPublisher.java:74) at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:786) at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:758) at hudson.model.Build$BuildExecution.post2(Build.java:183) at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:711) at hudson.model.Run.execute(Run.java:1690) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) at hudson.model.ResourceController.execute(ResourceController.java:88) at hudson.model.Executor.run(Executor.java:246) Finished: FAILURE

回答

1

使用pylint的同時,我遇到了一個類似的錯誤詹金斯。這似乎發生在Windows環境中,並且是Violations插件如何構建路徑的問題。如果您注意到您的錯誤,它會嘗試將您測試的文件的完整路徑添加到當前目錄(即C:\Jenkins\jobs\python-template-2\builds\2013-10-22_13-30-44\violations\file\<\failure>\<\testcase>)。

爲了解決這個問題,當我發生這種情況時,我寫了一個小腳本並在測試後運行它。它刪除了大部分路徑,只留下可添加到基本路徑的部分,而不會導致文件未找到錯誤。這裏是腳本:

with open('.\pylint_report.xml', 'r') as lint_file: 
    out = ''.join([line.replace('E:\\Jenkins\workspace\\', '') 
        for line in lint_file.readlines()]) 

with open('.\pylint_report.xml', 'w') as lint_file: 
    lint_file.write(out) 

你應該能夠適應你的具體使用情況。