Search code examples
pythonbddpython-behave

Python-behave tag's Or logic does not appear to be working


Feature: Addition tests

@one
Scenario: Add two numbers to pass
  Given two numbers to add
  When 2 and 3 are added together
  Then the sum should be 5

@two
  Scenario: Add two numbers to fail
  Given two numbers to add
  When 2 and 3 are added together
  Then the sum should be 6

Running >> behave --tags="@one" (or behave --tags=one) Gives me

@one
Scenario: Add two numbers to pass  # features/Add.feature:4
  Given two numbers to add         # features/steps/Maths.py:4 0.000s
  When 2 and 3 are added together  # features/steps/Maths.py:8 0.000s
  Then the sum should be 5         # features/steps/Maths.py:12 0.000s

 @two
 Scenario: Add two numbers to fail  # features/Add.feature:10
   Given two numbers to add         # None
   When 2 and 3 are added together  # None
   Then the sum should be 6         # None

As expected.

An yet Running >> behave --tags="@one or @two" Gives me

@one
Scenario: Add two numbers to pass  # features/Add.feature:4
  Given two numbers to add         # None
  When 2 and 3 are added together  # None
  Then the sum should be 5         # None

@two
Scenario: Add two numbers to fail  # features/Add.feature:10
  Given two numbers to add         # None
  When 2 and 3 are added together  # None
  Then the sum should be 6         # None

This should execute both scenarios and as per every tutorial this seems to be the way to run multiple scenarios. Am I missing something obvious here (and i'm definitely running "or" and not behave --tags="@one and @two")?


Solution

  • While this feature is documented in the latest version documentation, it is not available in the stable version, which at the time of writing this answer is 1.2.6. Your issue has been documented a while ago in github and closed.

    Chances are you have got version 1.2.6 or lower installed, in which case you should use one of the the following for logical OR:

    behave --tags=one,two
    
    #that's the same thing as
    behave --tags @one,@two
    

    behave --tags-help gives some useful info too.

    If you would like to upgrade, uninstall the current behave version and install the latest available tagged release (at this point in time v1.2.7.v1).

    sudo pip uninstall behave
    pip install git+https://github.com/behave/behave@v1.2.7.v1
    

    Instructions and other install options here.