pytest-bdd
pytest-bdd copied to clipboard
Feature/issue 234 add scenario attach method
Description:
-
Fix https://github.com/pytest-dev/pytest-bdd/issues/234, add scenario.attach method
-
Added scenario.attach method, so that you can add comments and/or screenshots to the cucumber-report.json file, and then you can convert the .json file to HTML report file
-
Referred to this https://github.com/gkushang/cucumber-html-reporter/blob/4ed7e774f93c54ecd71a051d414a6d30305694ec/lib/reporter.js , which will convert step.embeddings to
Show Info+
An example usage:
-
update your conftest.py by implementing the hook: pytest_bdd_after_scenario https://gist.github.com/kenhosr/3cb60efce5481d25967479e67f7edb76
-
run your test using: pytest --cucumber-json=cucumber_report.json
-
convert the .json to .html by following instructions here: https://github.com/gkushang/cucumber-html-reporter
Sample Report:

Codecov Report
Merging #329 into master will decrease coverage by
0.12%. The diff coverage is50%.
@@ Coverage Diff @@
## master #329 +/- ##
==========================================
- Coverage 95.64% 95.51% -0.13%
==========================================
Files 57 57
Lines 2202 2208 +6
Branches 184 184
==========================================
+ Hits 2106 2109 +3
- Misses 65 68 +3
Partials 31 31
| Impacted Files | Coverage Δ | |
|---|---|---|
| tests/feature/test_cucumber_json.py | 96.96% <ø> (ø) |
:arrow_up: |
| pytest_bdd/reporting.py | 92.42% <ø> (ø) |
:arrow_up: |
| pytest_bdd/cucumber_json.py | 92.85% <ø> (ø) |
:arrow_up: |
| tests/feature/test_report.py | 82.5% <ø> (ø) |
:arrow_up: |
| pytest_bdd/feature.py | 98.14% <50%> (-1.1%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update c6b16b6...4a09095. Read the comment docs.
found out an issue that when use Scenario Outline, it will attach data multiple times depending on the Examples table size. I will fix it later.
Hi! This branch will go to merged with master? Any prevision?
@kenhosr is it possible to revisit this one and freshen it up for merging? It seems like a very useful feature.
Also, the gist linked here seems incorrect/unrelated:
update your conftest.py by implementing the hook: pytest_bdd_after_scenario https://gist.github.com/kenhosr/3cb60efce5481d25967479e67f7edb76
could you freshen that up as well? Thank you!
And finally, an additional thought: pytest-nunit also has the add_nunit_attachment feature here... is it possible/beneficial to piggyback off of that if it exists, so as to reduce duplication?