从表现的测试结果中生成泡菜报告的最简单方法是什么?

发布于 2025-02-09 06:36:12 字数 246 浏览 2 评论 0 原文

我正在用表现 。我想生成一个 Pickles 报告。实现这一目标的最简单方法是什么?

I am writing behavior tests in python with behave. I would like to generate a pickles report. What is the simplest way to achieve that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提赋 2025-02-16 06:36:12

有多种可能性,每种都有自己的优势和不便。

Pickles支持Xunit,Nunit和Cucumber-Json报告等。因此,我需要找到一种方法,以其中一种形式的方式来获取报告。 Xunit和Nunit是.NET特定格式,因此它们与Python没有关系。但是,行为支持JSON输出。不幸的是,Beht的JSON输出不是Cucumber-Json格式腌制的期望。

通过XSLT转换,将JUNIT测试报告转换为Nunit报告

行为支持 Junit ,并且可以通过XSLT转换将Junit Test转换为Nunit。根据这篇文章,有一个(可能过时的)XSLT变换在这里。可以使用Apache Ant进行这样的转换,这很棒,因为我正在使用这种构建类型的团队合作。在Kotlin DSL中,这意味着我可以使用

steps {

  [whatever script steps or other stuff]

  ant {
    mode = antScript {
      content = """
        <target name="transform" description="Run functional tests">
          <xslt in="${'

该方法的问题更新我的构建步骤,即如果我想测试这样的脚本,我需要在开发PC上安装很多Java东西,并且我不太喜欢爪哇东西。除此之外,还有此NPM软件包这可能会有所帮助。它没有很多星星,但可能会很好。总而言之,我对XSLT不太满意,因此我不喜欢这种解决方案。

使用 behave2cumber2cumber

包装名称听起来很棒,并且使用它似乎很容易。因此,这是我首选的解决方案。就像奏效的那样简单

pip install behave2cucumber
behave --format=json -o json-report.json /path/to/features
python -m behave2cucumber -i json-report.json -o cucumber-report.json

,我会很高兴,因为从本质上讲,PYPI的所有内容都可以从中获得,听起来真的很棒。但是,我所有的背景步骤都标记为在我的 cucumber-report.json 输出中跳过没有显示我方案的正确状态。

写下我自己的自定义格式化器

以下这个github问题,我偶然发现了一些解释some code (相同的代码)。 Here are the steps it took me to make it work:

  1. copy / paste the
  2. 运行
behave --format=behave.formatter.cucumber_json:PrettyCucumberJSONFormatter -o cucumber-report.json /path/to/features

,并且可以像魅力一样工作。因为我在许多项目中都需要这个格式化器,所以我的下一步将是生产一个可以在这些项目中安装的Python软件包并参考类似的内容:

# run_behave.py
import os

from behave.configuration import Configuration
from behave.formatter import _registry
from behave.runner import Runner
from my_formatter_package import PrettyCucumberJSONFormatter

here = os.path.dirname(os.path.abspath(__file__))

_registry.register_as("PrettyCucumberJSONFormatter", PrettyCucumberJSONFormatter)
configuration = Configuration(junit_directory="behave_reports")
configuration.format = ["PrettyCucumberJSONFormatter"]
configuration.stdout_capture = False
configuration.stderr_capture = False
configuration.paths = [os.path.join(here, "features")]
Runner(configuration).run()

这应该可以解决问题。这种方法的不便是我需要维护自己的格式化器。我不知道将来将在JSON输出中改变哪些新的表现版本,以及 cucumber-json架构会随着时间的推移而发展。希望这个格式化将被集成到行为

}{PATH_TO_THE_JUNIT_FILE}" out="${'

该方法的问题更新我的构建步骤,即如果我想测试这样的脚本,我需要在开发PC上安装很多Java东西,并且我不太喜欢爪哇东西。除此之外,还有此NPM软件包这可能会有所帮助。它没有很多星星,但可能会很好。总而言之,我对XSLT不太满意,因此我不喜欢这种解决方案。

使用 behave2cumber2cumber

包装名称听起来很棒,并且使用它似乎很容易。因此,这是我首选的解决方案。就像奏效的那样简单


,我会很高兴,因为从本质上讲,PYPI的所有内容都可以从中获得,听起来真的很棒。但是,我所有的背景步骤都标记为在我的 cucumber-report.json 输出中跳过没有显示我方案的正确状态。

写下我自己的自定义格式化器

以下这个github问题,我偶然发现了一些解释some code (相同的代码)。 Here are the steps it took me to make it work:

  1. copy / paste the
  2. 运行

,并且可以像魅力一样工作。因为我在许多项目中都需要这个格式化器,所以我的下一步将是生产一个可以在这些项目中安装的Python软件包并参考类似的内容:


这应该可以解决问题。这种方法的不便是我需要维护自己的格式化器。我不知道将来将在JSON输出中改变哪些新的表现版本,以及 cucumber-json架构会随着时间的推移而发展。希望这个格式化将被集成到行为

}{PATH_TO_THE_NUNIT_FILE}" style="junit-to-nunit.xsl" /> </target> """.trimIndent() } targets = "transform" } }

该方法的问题更新我的构建步骤,即如果我想测试这样的脚本,我需要在开发PC上安装很多Java东西,并且我不太喜欢爪哇东西。除此之外,还有此NPM软件包这可能会有所帮助。它没有很多星星,但可能会很好。总而言之,我对XSLT不太满意,因此我不喜欢这种解决方案。

使用 behave2cumber2cumber

包装名称听起来很棒,并且使用它似乎很容易。因此,这是我首选的解决方案。就像奏效的那样简单


,我会很高兴,因为从本质上讲,PYPI的所有内容都可以从中获得,听起来真的很棒。但是,我所有的背景步骤都标记为在我的 cucumber-report.json 输出中跳过没有显示我方案的正确状态。

写下我自己的自定义格式化器

以下这个github问题,我偶然发现了一些解释some code (相同的代码)。 Here are the steps it took me to make it work:

  1. copy / paste the
  2. 运行

,并且可以像魅力一样工作。因为我在许多项目中都需要这个格式化器,所以我的下一步将是生产一个可以在这些项目中安装的Python软件包并参考类似的内容:


这应该可以解决问题。这种方法的不便是我需要维护自己的格式化器。我不知道将来将在JSON输出中改变哪些新的表现版本,以及 cucumber-json架构会随着时间的推移而发展。希望这个格式化将被集成到行为

There multiple possibilities, each coming with its own advantages and inconvenients.

Pickles supports xUnit, NUnit, and cucumber-json reports, among others. So I need to find a way to get a report from behave in one of those formats. xUnit and NUnit are .NET-specific formats, so they have no relation with python. Behave supports, however, json output. Unfortunately, behave's json output is not the cucumber-json format pickles expects.

Convert JUnit test reports into NUnit reports through an XSLT transformation

Of course, behave supports JUnit and it's possible to convert the JUnit test to NUnit through an XSLT transformation. According to this post, there is a (possibly outdated) XSLT transformation here. Such a transformation can be carried out with Apache Ant, which is great, because I am working on TeamCity which comes with a build type of that kind. In Kotlin DSL, this means I could update my build step with something like

steps {

  [whatever script steps or other stuff]

  ant {
    mode = antScript {
      content = """
        <target name="transform" description="Run functional tests">
          <xslt in="${'

The problem with that approach is that I need to install a lot of Java stuff on my development PC if I want to test such a script and I am not very fond of Java stuff. Other than that, there is this npm package that could help. It has not a lot of stars, but it might work well. To sum up, I am not very comfortable with XSLTs, therefore I don't like this solution.

Use behave2cucumber

The package name sounds really great, and using it seems very easy. So this was a priori my preferred solution. It is as simple as

pip install behave2cucumber
behave --format=json -o json-report.json /path/to/features
python -m behave2cucumber -i json-report.json -o cucumber-report.json

If that worked, I would've been so happy, because essentially everything is available from pypi, sounds really great. However, all my Background steps were flagged as skipped in my cucumber-report.json output, making that solution a no-go, because it doesn't show the right status of my scenarios.

Write my own custom formatter

Following this github issue, I stumbled upon some explanations and some code (same code here). Here are the steps it took me to make it work:

  1. copy / paste the code into file venv/Lib/site-packages/behave/formatter/cucumber_json.py
  2. run
behave --format=behave.formatter.cucumber_json:PrettyCucumberJSONFormatter -o cucumber-report.json /path/to/features

And that works like a charm. Because I need this formatter in many projects, my next steps will be to produce a python package that I can install in those projects and reference something like this:

# run_behave.py
import os

from behave.configuration import Configuration
from behave.formatter import _registry
from behave.runner import Runner
from my_formatter_package import PrettyCucumberJSONFormatter

here = os.path.dirname(os.path.abspath(__file__))

_registry.register_as("PrettyCucumberJSONFormatter", PrettyCucumberJSONFormatter)
configuration = Configuration(junit_directory="behave_reports")
configuration.format = ["PrettyCucumberJSONFormatter"]
configuration.stdout_capture = False
configuration.stderr_capture = False
configuration.paths = [os.path.join(here, "features")]
Runner(configuration).run()

And that should do the trick. The inconvenient of that approach is that I need to maintain my own formatter. I don't know what new behave versions will change in the json output in the future and how the cucumber-json schema will evolve with time. Hopefully this formatter will get integrated to behave.

}{PATH_TO_THE_JUNIT_FILE}" out="${'

The problem with that approach is that I need to install a lot of Java stuff on my development PC if I want to test such a script and I am not very fond of Java stuff. Other than that, there is this npm package that could help. It has not a lot of stars, but it might work well. To sum up, I am not very comfortable with XSLTs, therefore I don't like this solution.

Use behave2cucumber

The package name sounds really great, and using it seems very easy. So this was a priori my preferred solution. It is as simple as


If that worked, I would've been so happy, because essentially everything is available from pypi, sounds really great. However, all my Background steps were flagged as skipped in my cucumber-report.json output, making that solution a no-go, because it doesn't show the right status of my scenarios.

Write my own custom formatter

Following this github issue, I stumbled upon some explanations and some code (same code here). Here are the steps it took me to make it work:

  1. copy / paste the code into file venv/Lib/site-packages/behave/formatter/cucumber_json.py
  2. run

And that works like a charm. Because I need this formatter in many projects, my next steps will be to produce a python package that I can install in those projects and reference something like this:


And that should do the trick. The inconvenient of that approach is that I need to maintain my own formatter. I don't know what new behave versions will change in the json output in the future and how the cucumber-json schema will evolve with time. Hopefully this formatter will get integrated to behave.

}{PATH_TO_THE_NUNIT_FILE}" style="junit-to-nunit.xsl" /> </target> """.trimIndent() } targets = "transform" } }

The problem with that approach is that I need to install a lot of Java stuff on my development PC if I want to test such a script and I am not very fond of Java stuff. Other than that, there is this npm package that could help. It has not a lot of stars, but it might work well. To sum up, I am not very comfortable with XSLTs, therefore I don't like this solution.

Use behave2cucumber

The package name sounds really great, and using it seems very easy. So this was a priori my preferred solution. It is as simple as


If that worked, I would've been so happy, because essentially everything is available from pypi, sounds really great. However, all my Background steps were flagged as skipped in my cucumber-report.json output, making that solution a no-go, because it doesn't show the right status of my scenarios.

Write my own custom formatter

Following this github issue, I stumbled upon some explanations and some code (same code here). Here are the steps it took me to make it work:

  1. copy / paste the code into file venv/Lib/site-packages/behave/formatter/cucumber_json.py
  2. run

And that works like a charm. Because I need this formatter in many projects, my next steps will be to produce a python package that I can install in those projects and reference something like this:


And that should do the trick. The inconvenient of that approach is that I need to maintain my own formatter. I don't know what new behave versions will change in the json output in the future and how the cucumber-json schema will evolve with time. Hopefully this formatter will get integrated to behave.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文