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

Filtering by tags fails if scenario outline with examples tables are used #47

Closed rbcasperson closed 2 years ago

rbcasperson commented 2 years ago

As documented, we support building docs for a subset of features, based on tags. However there is a bug when doing that:

Traceback (most recent call last):
  File "/py3.7/bin/sphinx-gherkindoc", line 8, in <module>
    sys.exit(main())
  File "/py3.7/lib/python3.7/site-packages/sphinx_gherkindoc/cli.py", line 306, in main
    process_args(args, gherkin_path, output_path, args.doc_project)
  File "/py3.7/lib/python3.7/site-packages/sphinx_gherkindoc/cli.py", line 130, in process_args
    exclude_tags=args.exclude_tags,
  File "/py3.7/lib/python3.7/site-packages/sphinx_gherkindoc/writer.py", line 366, in feature_to_rst
    included_scenarios = get_all_included_scenarios(feature, include_tags, exclude_tags)
  File "/py3.7/lib/python3.7/site-packages/sphinx_gherkindoc/utils.py", line 322, in get_all_included_scenarios
    for scenario in feature.scenarios
  File "/py3.7/lib/python3.7/site-packages/sphinx_gherkindoc/utils.py", line 322, in <genexpr>
    for scenario in feature.scenarios
  File "/py3.7/lib/python3.7/site-packages/sphinx_gherkindoc/utils.py", line 266, in _scenario_if_included
    scenario.examples = included_examples
AttributeError: can't set attribute

The issue here is that we always set the scenario examples: https://github.com/jolly-good-toolbelt/sphinx_gherkindoc/blob/master/sphinx_gherkindoc/utils.py#L265

BUT, the pytest-bdd Scenario model class does not have a setter, when a @property is used for examples. This is the cause of the above error. In fact, it currently shouldn't even work for Behave, because the base model does not have a way to appropriately set attributes: https://github.com/jolly-good-toolbelt/sphinx_gherkindoc/blob/master/sphinx_gherkindoc/parsers/base.py#L25

Here's the real kicker! This test case is actually covered, but there is a typo in the tests. This logic actually tests the same thing twice. The second part should use examples instead of tags. If you correct that, the tests fail.

So there are two issues really: 1) The pytest-bdd scenario model doesn't have a way to set examples. This actually doesn't matter because pytest-bdd doesn't support taggind Examples tables anyway. So the underlying issue is that we overwrite the examples attribute no matter what: https://github.com/jolly-good-toolbelt/sphinx_gherkindoc/blob/master/sphinx_gherkindoc/utils.py#L265 2) Overwriting the examples doesn't work anyway, because there is no logic to correctly set the attribute so that it is read.