Skip to content

Ensure that current JSONFormatter data is written in cases where run is aborted.#843

Open
wombat70 wants to merge 1 commit intobehave:mainfrom
wombat70:fix-json-incomplete-on-abort
Open

Ensure that current JSONFormatter data is written in cases where run is aborted.#843
wombat70 wants to merge 1 commit intobehave:mainfrom
wombat70:fix-json-incomplete-on-abort

Conversation

@wombat70
Copy link
Copy Markdown

@wombat70 wombat70 commented Jun 17, 2020

Ref. #842

… data is written by JSONFormatter, in cases where where run is aborted.
@wombat70 wombat70 changed the title Ensure that formatter.eof() is called, to ensure that current feature… Ensure that current JSONFormatter data is written in cases where run is aborted. Jun 18, 2020
@wombat70
Copy link
Copy Markdown
Author

Ref issue #842, when I run behave in a similar way with this patch in place, I get a good JSON output:

$ behave features/abort.feature --format json.pretty --outfile result.json

ABORTED: By user.

Failing scenarios:
  features/abort.feature:8  This failing scenario is tagged to abort on failure.

0 features passed, 1 failed, 0 skipped
0 scenarios passed, 1 failed, 0 skipped
1 step passed, 1 failed, 1 skipped, 0 undefined
Took 0m0.000s

The result.json I get correctly includes the current (failing) feature:

$ cat result.json
[
{
  "description": [
    "In order to be able to debug an application", 
    "As a test engineer", 
    "I want to be able to abort a test run and get a complete JSON result file."
  ], 
  "elements": [
    {
      "keyword": "Example", 
      "location": "features/abort.feature:8", 
      "name": "This failing scenario is tagged to abort on failure.", 
      "status": "failed", 
      "steps": [
        {
          "keyword": "Given", 
          "location": "features/abort.feature:9", 
          "match": {
            "arguments": [], 
            "location": "features/steps/abort_steps.py:5"
          }, 
          "name": "this step passes", 
          "result": {
            "duration": 7.796287536621094e-05, 
            "status": "passed"
          }, 
          "step_type": "given"
        }, 
        {
          "keyword": "When", 
          "location": "features/abort.feature:10", 
          "match": {
            "arguments": [], 
            "location": "features/steps/abort_steps.py:10"
          }, 
          "name": "this step fails", 
          "result": {
            "duration": 0.00019598007202148438, 
            "error_message": "Assertion Failed: Step failed!", 
            "status": "failed"
          }, 
          "step_type": "when"
        }, 
        {
          "keyword": "Then", 
          "location": "features/abort.feature:11", 
          "name": "this step passes", 
          "step_type": "then"
        }
      ], 
      "tags": [
        "abort_on_fail"
      ], 
      "type": "scenario"
    }
  ], 
  "keyword": "Feature", 
  "location": "features/abort.feature:1", 
  "name": "Test behave abort behaviour.", 
  "status": "failed", 
  "tags": []
}
]

@stale
Copy link
Copy Markdown

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 26, 2021
@bittner
Copy link
Copy Markdown
Member

bittner commented Jun 26, 2021

@jenisys This change seems simple enough to be easily merged. Shall I proceed?

@stale stale bot removed the wontfix label Jun 26, 2021
@jenisys
Copy link
Copy Markdown
Member

jenisys commented Jun 26, 2021

Have you checked that no side-effects occur on any formatter class when its formatter.eof() function is called twice?

PROBLEMATIC FORMATTERS:

  • pretty
  • progress

POTENTIAL SOLUTIONS:

  • Adapt/fix formatter(s)
  • Use formatter.eof() only in ABORTED case

@jenisys jenisys force-pushed the main branch 5 times, most recently from 6508bd4 to a4dd3fe Compare March 6, 2022 23:33
@jenisys jenisys force-pushed the main branch 2 times, most recently from 11ddaf9 to 5101465 Compare May 2, 2022 19:16
@jenisys jenisys force-pushed the main branch 3 times, most recently from 7ec93d2 to 46ad983 Compare November 6, 2022 14:11
@jenisys jenisys force-pushed the main branch 4 times, most recently from fe1ca4d to fcfe5af Compare April 22, 2023 17:20
@jenisys jenisys force-pushed the main branch 2 times, most recently from 0a4d73b to 2c11d2e Compare May 14, 2024 22:39
@jenisys jenisys force-pushed the main branch 2 times, most recently from 3e51dda to c6ab01c Compare May 26, 2024 15:00
@jenisys jenisys force-pushed the main branch 2 times, most recently from eccf022 to 93e1218 Compare June 16, 2024 16:10
@jenisys jenisys force-pushed the main branch 2 times, most recently from cc16ac0 to 22569f4 Compare October 14, 2024 20:09
@jenisys jenisys force-pushed the main branch 2 times, most recently from 01407cf to 42e64a9 Compare October 24, 2024 23:28
@jenisys jenisys force-pushed the main branch 9 times, most recently from 9dc617b to b8b23bc Compare July 16, 2025 21:43
@jenisys jenisys force-pushed the main branch 4 times, most recently from 612d6d1 to 5796057 Compare August 4, 2025 06:58
@jenisys jenisys force-pushed the main branch 6 times, most recently from 370ce68 to cba3c4f Compare August 31, 2025 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants