【问题标题】:Violations plugin uses wrong path to find pep8 reportViolations 插件使用错误的路径来查找 pep8 报告
【发布时间】:2013-10-31 03:52:10
【问题描述】:

我正在使用 pytest 运行 pep8 检查(下面列出的所有内容都发生在 Windows 机器上):

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

我设置了一个作业来在reports\pep8.log 中查找pep8.log 文件

但是当我运行作业时,我发现违规插件查找报告的路径没有意义:

生成的xml文件: C:\Jenkins\jobs\python-template-2\workspace\reports\pep8.log =============== 89 次失败,33 次跳过,1.48 秒内错误 1 ​​次 =================

C:\Jenkins\jobs\python-template-2\workspace>exit 1 构建步骤 'Выполнить команду Windows' 将构建标记为失败 错误:发布者 hudson.plugins.violations.ViolationsPublisher 由于异常 java.io.FileNotFoundException 而中止: C:\Jenkins\jobs\python-template-2\builds\2013-10-22_13-30-44\violations\file\C:\Jenkins\jobs\python-template-2\工作区\竞赛\迁移\0003_auto__add_votinghistory.py.xml (文件名中的语法错误) 在 java.io.FileOutputStream.open(Native 方法)在 java.io.FileOutputStream.(Unknown Source) at java.io.FileOutputStream.(Unknown Source) at hudson.FilePath.write(FilePath.java:1642) 在 hudson.plugins.violations.generate.ExecuteFilePath.execute(ExecuteFilePath.java:40) 在 hudson.plugins.violations.generate.GenerateXML.execute(GenerateXML.java:47) 在 hudson.plugins.violations.ViolationsCollector.invoke(ViolationsCollector.java:122) 在 hudson.plugins.violations.ViolationsCollector.invoke(ViolationsCollector.java:25) 在 hudson.FilePath.act(FilePath.java:912) 在 hudson.FilePath.act(FilePath.java:885) 在 hudson.plugins.violations.ViolationsPublisher.perform(ViolationsPublisher.java:74) 在 hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45) 在 hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:781) 在 hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:753) 在 hudson.model.Build$BuildExecution.post2(Build.java:183) 在 hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:706) 在 hudson.model.Run.execute(Run.java:1690) 在 hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) 在 hudson.model.ResourceController.execute(ResourceController.java:88) 在 hudson.model.Executor.run(Executor.java:230) 完成:失败

另外,我尝试在不使用 pytest 的情况下启动 pep8 检查,而是使用此命令在 windows 上查找并检查所有 .py 文件:

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

在这种情况下,我得到以下信息:

C:\Jenkins\jobs\python-template-2\workspace>exit 1 构建步骤 'Выполнить команду Windows' 将构建标记为失败错误:发布者 hudson.plugins.violations.ViolationsPublisher 由于异常而中止 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 (文件名中的语法错误) 在 java.io.FileOutputStream.open(Native 方法)在 java.io.FileOutputStream.(Unknown Source) at java.io.FileOutputStream.(Unknown Source) at hudson.FilePath.write(FilePath.java:1666) 在 hudson.plugins.violations.generate.ExecuteFilePath.execute(ExecuteFilePath.java:40) 在 hudson.plugins.violations.generate.GenerateXML.execute(GenerateXML.java:47) 在 hudson.plugins.violations.ViolationsCollector.invoke(ViolationsCollector.java:122) 在 hudson.plugins.violations.ViolationsCollector.invoke(ViolationsCollector.java:25) 在 hudson.FilePath.act(FilePath.java:916) 在 hudson.FilePath.act(FilePath.java:889) 在 hudson.plugins.violations.ViolationsPublisher.perform(ViolationsPublisher.java:74) 在 hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45) 在 hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:786) 在 hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:758) 在 hudson.model.Build$BuildExecution.post2(Build.java:183) 在 hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:711) 在 hudson.model.Run.execute(Run.java:1690) 在 hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) 在 hudson.model.ResourceController.execute(ResourceController.java:88) 在 hudson.model.Executor.run(Executor.java:246) 完成:失败

【问题讨论】:

    标签: python windows jenkins pytest pep8


    【解决方案1】:

    我在 Jenkins 中使用 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)
    

    您应该能够根据您的特定用例进行调整。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-12
      • 2017-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多