jolly-good-toolbelt / sphinx_gherkindoc

A tool to convert Gherkin into Sphinx documentation
https://jolly-good-toolbelt.github.io/sphinx_gherkindoc/
11 stars 10 forks source link

Fix: better pytest-bdd feature description handling #32

Closed bbrownjc closed 4 years ago

bbrownjc commented 4 years ago

Addresses 2 issues reported by @rbcasperson:

(1) a Feature file with no description would cause an error

  File "/Users/rcasperson/Library/Caches/pypoetry/virtualenvs/jumpcloud-acceptance-5DpiQ84h-py3.7/bin/sphinx-gherkindoc", line 8, in <module>
    sys.exit(main())
  File "/Users/rcasperson/Library/Caches/pypoetry/virtualenvs/jumpcloud-acceptance-5DpiQ84h-py3.7/lib/python3.7/site-packages/sphinx_gherkindoc/cli.py", line 278, in main
    process_args(args, gherkin_path, output_path, args.doc_project)
  File "/Users/rcasperson/Library/Caches/pypoetry/virtualenvs/jumpcloud-acceptance-5DpiQ84h-py3.7/lib/python3.7/site-packages/sphinx_gherkindoc/cli.py", line 127, in process_args
    background_step_format=args.background_step_format,
  File "/Users/rcasperson/Library/Caches/pypoetry/virtualenvs/jumpcloud-acceptance-5DpiQ84h-py3.7/lib/python3.7/site-packages/sphinx_gherkindoc/writer.py", line 350, in feature_to_rst
    steps(feature.background.steps, step_format=background_step_format)
  File "/Users/rcasperson/Library/Caches/pypoetry/virtualenvs/jumpcloud-acceptance-5DpiQ84h-py3.7/lib/python3.7/site-packages/sphinx_gherkindoc/parsers/base.py", line 24, in __getattr__
    return getattr(self._data, key)
AttributeError: 'NoneType' object has no attribute 'steps'

due to our pytest-bdd parser always returning our custom Background class wrapper even if feature.background == None

(2) A multi-line description via the pytest-bdd parser would fail insphinx-build

Warning, treated as error:
/Users/rcasperson/go/src/github.com/TheJumpCloud/jumpcloud-acceptance/bdd_docs/_docs_working/adbridge.create_user_in_ad.feature-file.rst:21:Inline interpreted text or phrase reference start-string without end-string.

due to a variance in the way pytest-bdd and behave pass descriptions -- where behave returns a list of newline-stripped strings, pytest-bdd returns a single string with newlines embedded. To align this, we can pre-split the description in our pytest_bdd.Feature wrapper class.

These changes have been tested as functional against the private team repo from which @rbcasperson reported the issue, and with them the docs for that repo succesfully build.