Skip to content

Fatal error when using --format=json #59

Closed

Description

@quantoid

Use of "behave --format=json" fails with reference to undefined method:

Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\lib\site-packages\behave-1.1.0-py2.7.egg\behave\__main__.py", line 116, in <module>
main()
  File "C:\Python27\lib\site-packages\behave-1.1.0-py2.7.egg\behave\__main__.py", line 90, in main
    failed = runner.run()
  File "C:\Python27\lib\site-packages\behave-1.1.0-py2.7.egg\behave\runner.py", line 419, in run
    self.run_with_paths()
  File "C:\Python27\lib\site-packages\behave-1.1.0-py2.7.egg\behave\runner.py", line 444, in run_with_paths
    failed = feature.run(self)
  File "C:\Python27\lib\site-packages\behave-1.1.0-py2.7.egg\behave\model.py", line 238, in run
    failed = scenario.run(runner)
  File "C:\Python27\lib\site-packages\behave-1.1.0-py2.7.egg\behave\model.py", line 431, in run
    runner.formatter.step(step)
  File "C:\Python27\lib\site-packages\behave-1.1.0-py2.7.egg\behave\formatter\json.py", line 50, in step
    element['steps'].append(step.to_dict())
AttributeError: 'dict' object has no attribute 'to_dict'

Activity

  1. quantoid commented on Aug 16, 2012

    @quantoid
    Author

    This is because the Scenario model object is being modified by the JSONFormatter in the step() method, since it is the last element returned by _feature_element():

    def step(self, step):
        element = self._feature_element()
        if 'steps' not in element:
            element['steps'] = []
        element['steps'].append(step.to_dict())
    

    So the Step gets converted to a dict and added to the Scenario, which causes Scenario.run to call the formatter with this added dict as if it were another step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions