diff --git a/sphinx_needs/roles/need_count.py b/sphinx_needs/roles/need_count.py index 2bb861f74..06ee0d472 100644 --- a/sphinx_needs/roles/need_count.py +++ b/sphinx_needs/roles/need_count.py @@ -59,7 +59,7 @@ def process_need_count( need_list, needs_config, filters[1], location=node_need_count ) ) - amount = f"{amount_1 / amount_2 * 100:2.1f}" + amount = "inf" if amount_2 == 0 else f"{amount_1 / amount_2 * 100:2.1f}" elif len(filters) > 2: raise NeedsInvalidFilter( "Filter not valid. Got too many filter elements. Allowed are 1 or 2. " diff --git a/tests/doc_test/doc_need_count/index.rst b/tests/doc_test/doc_need_count/index.rst index eb5d2bfcc..9cc624f94 100644 --- a/tests/doc_test/doc_need_count/index.rst +++ b/tests/doc_test/doc_need_count/index.rst @@ -23,3 +23,7 @@ result_1-:need_count:`"A" in tags` result_2-:need_count:`"B" in tags` result_3-:need_count:`True` + +result_4-:need_count:`"A" in tags ? "B" in tags` + +result_5-:need_count:`"A" in tags ? "X" in tags` diff --git a/tests/test_need_count.py b/tests/test_need_count.py index 7d0883d4f..3d03839b6 100644 --- a/tests/test_need_count.py +++ b/tests/test_need_count.py @@ -15,3 +15,5 @@ def test_doc_need_count(test_app): assert "result_1-3" in html assert "result_2-2" in html assert "result_3-4" in html + assert "result_4-1" in html + assert "result_5-inf" in html