Skip to content

Update to 1.15 - compatible with behave version 1.3.0 #97

Merged
modehnal merged 14 commits intomainfrom
fp/behave_1_3_0
Aug 20, 2025
Merged

Update to 1.15 - compatible with behave version 1.3.0 #97
modehnal merged 14 commits intomainfrom
fp/behave_1_3_0

Conversation

@modehnal
Copy link
Copy Markdown
Collaborator

Fix behave version to 1.3.0.
Fix before scenario step handling (new behave calls methods in reverse).
Add default background to unhandled scenario status.
Support late registration of formatter in before_scenario. Closes #94
Fix dependency on external tools in tests. Closes #96

@modehnal modehnal requested a review from fpokryvk August 15, 2025 12:00
@modehnal
Copy link
Copy Markdown
Collaborator Author

@jenisys Would you know why the tests are failing like this? https://github.com/behave-contrib/behave-html-pretty-formatter/actions/runs/16989669598?pr=97

KeyError: "'__name__' not in globals"

I am trying to figure out where the problems is but no luck for now. Perhaps you also dealt with in behave?

@modehnal
Copy link
Copy Markdown
Collaborator Author

I mean, I can add to all files that the problem is in:

if "__name__" not in globals():
    __name__ = "__main__"

but something is weird here, how did the main got removed from globals?

@modehnal
Copy link
Copy Markdown
Collaborator Author

@jenisys Alright, it seems somewhere between 1.2.6 and 1.3.0 something got broken with globals in tests/acceptance. Do you have any idea where the issue might be? The 1.3.1 fails, the 1.3.0 fails, the 1.2.6 is alright, as can be seen here.

Reverting back to 1.3.1

@jenisys
Copy link
Copy Markdown
Member

jenisys commented Aug 17, 2025

Mmh, what should I say:

  • Never ever put a Python package in the steps directory, meaning: behave4cmd0
  • A Python package or step-library belongs somewhere, where it is in the Python search path.
  • Use PYTHONPATH=$PWD environment variable and place it into the root-directory of the repo or similar (or install them globally or in a virtual-environment).
  • For example, use direnv to ensure that the environment is set up when you enter the repo directory.

WHAT IS THE PROBLEM (the failures in the CI test run):

  • Relative imports, like from . import command_steps, can only be used within a Python package, but not in Python module or Python scripts.
  • Because you placed behave4cmd0 under the steps directory (and @bittner merged a pull-request that recursively imports step-modules below the steps directory), this constraint is violated now. Steps are basically loaded like Python module/script and not a Python package.

ADDITIONAL FIXES THAT I NEEDED:

# -- FILE: tests/acceptance/features/help-screen.feature
...
     Then it should pass
     And the command output should contain:
       """
-      Available formatters:
+      AVAILABLE FORMATTERS:
+        captured       Inspect captured output.
         html-pretty    Pretty HTML Formatter
         json           JSON dump of test run
       """
# -- FILE: tests/acceptance/features/html-output.feature
# NEEDED: feature-file, steps-directory even in dry-run mode
...
+    And a file named "features/steps/use_behave4cmd0_steps.py" with:
+      """
+      from behave4cmd0 import passing_steps
+      """
+    And a file named "features/passing.feature" with:
+      """
+      Feature: Passing
+        Scenario: One
+          Given a step passes
+          When another step passes
+      """
     When I run "behave --format html-pretty --dry-run"
     Then it should pass
     And the command output should contain:
# -- FILE: tests/formatter_features/behave.ini
+[behave]
+default_format = pretty
+# -- ENSURE: At least one html-pretty formatter is used.
+format = html-pretty
+output = report.html
...

@modehnal
Copy link
Copy Markdown
Collaborator Author

@jenisys thank you, these hints were very useful.

Since I did not setup the behave4cmd0, it did not occur to me it could be the reason (this kind of error is a first for me, next time I will know what to focus on). Moving the behave4cmd0 from steps and some minor changes were enough to fix it.

Copy link
Copy Markdown
Collaborator

@fpokryvk fpokryvk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@fpokryvk fpokryvk self-assigned this Aug 20, 2025
@fpokryvk fpokryvk self-requested a review August 20, 2025 08:48
@modehnal modehnal merged commit 8fd65cc into main Aug 20, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Missing test dependency: qecore Formatter breaks with internal behave API with behave > 1.2.6.

3 participants