Skip to content

JSONFormatter has several problems #60

Closed

Description

@jenisys

DEVELOPMENT-SNAPSHOT: 2012-08-17 (after fixes for issue #59)

The JSONFormatter has currently several problems
(using it "behave --format=json ...").

PROBLEM 1:

Last feature is outputted twice.

REASON:
formatter.eof() is called twice for last feature:

  • once at end of Feature.run() and
  • once at end of Runner.run()

JSONFormatter currently detects not that no additional data was entered in between these 2 calls.
NOTE:
These 2 calls are not bad. They allow the Formatter class a finalize-output feature that is sometimes needed (as long as no other method exists for this).

PROBLEM 2:

Invalid JSON output is generated/returned.

CURRENT-OUTPUT-SCHEMA:
{ $feature1 }{ $featue2 }...{ $featureN }

USE-SCHEMA: 
[ { $feature1 }, ..., { $featureN } ]

MINOR ISSUES:

Unformatted JSON output is unreadable.
Prettify output with json.dumps(x, indent=2) or json.dumps(x, indent=2, sort_keys=True)

Summary formatter output is mingled with JSON data, even when --output option is used.
This leads again to invalid JSON output that must be seperated from JSON data.
DESIRED-CHANGE: Only JSON output is written into output file (or more general: Only from one formatter)

Activity

  1. jenisys commented on Aug 21, 2012

    @jenisys
    MemberAuthor

    Before retesting (after inspecting the changes)

    IMHO, this will not work to solve the JSON output problem described in issue #60.
    I looked into this problem after I wrote the trouble-ticket.

    behave.runner.Runner.run_with_path() creates a new formatter object for each iteration in the feature processing loop. Therefore, exactly one feature is processed by each JSONFormatter instance. Maybe it would be better to have a JSON reporter !?!
    It seems just like another output format, like the junit (XML) reporter.

    After retesting

    After testing it with release-1.2.2, my worries, stated above, are confirmed.
    PROBLEM 1 is fixed.
    PROBLEM 2 is not fixed.
    Therefore, non-JSON compliant output is generated.

  2. added a commit that references this issue on Sep 1, 2012
    8355b79
  3. ghost assigned on Apr 27, 2013
  4. jenisys commented on Apr 27, 2013

    @jenisys
    MemberAuthor

    Problem 2 is now finally fixed.
    Formatters are now created only once (was: once for each feature).
    JSON formatter writes now feature data triggered by formatter.eof() and final JSON footer when formatter is closed.
    Well-formed JSON output is now generated.

    FUTURE:
    Provide *.jsonschema to validate generated JSON output (and detect implementation problems early on)

  5. added a commit that references this issue on Apr 28, 2013
  6. added a commit that references this issue on Aug 28, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions