Questions tagged [python-behave]

Behave is a BDD framework for Python, based on the Cucumber Framework.

Behave is Behaviour Driven Development (BDD) framework for Python. It follows the Gherkin syntax, which defines Scenarios and steps files.

A scenario is a human readable flow, for example:

Scenario: Calling the metadata API
   Given A matching server
   When I call metadata
   Then metadata response is JSON
   And response status code is 200

The steps file casts programmatic meaning to each line, for example:

...
@then('response status code is {expected_status_code}')
def step_impl(context, expected_status_code):
    assert_equals(context.response.status_code, int(expected_status_code))

@then('metadata response is JSON')
def step_impl(context):
    json.loads(context.metadata_response.data)
...

Behave combines the scenario and steps to a test report:

enter image description here

521 questions
53
votes
8 answers

How can I see print() statements in behave (BDD)

Context: I am using Python with Behave (BDD). Whether I run my tests from the command line (behave) or from a custom main(), the behavior is the same: the test runs and the only output that I see in the console is the standard BDD report. My tests…
Ben
  • 1,205
  • 1
  • 9
  • 14
43
votes
5 answers

In behave, how do you run a scenario only?

I have a 'behave' feature that has a lot of tests on it. I only need to run a specific scenario for development needs. How do I do it? (preferably on the command line)
Mark Lopez
  • 770
  • 1
  • 6
  • 10
22
votes
2 answers

How to integrate behave into pytest?

I create a Django app and heavily rely on pytest to discover and organize my unit and functional tests. However, I want to apply Behaviour Driven with behave Development for future tests. Unfortunately, the behave test features are not auto-detected…
Jon
  • 11,356
  • 5
  • 40
  • 74
22
votes
4 answers

passing command line argument to python-behave

I am using python-behave for BDD testing, I have to pass an URL (e.g. www.abc.com) from command line. $behave -u "www.abc.com" To achieve this, I have read behave documentation but there are not enough materials as well as explanations given for…
user3375505
  • 251
  • 1
  • 3
  • 7
21
votes
4 answers

pip install FileNotFoundError: [Errno 2] No such file or directory:

I am trying to install behave-parallel using pip install. I have installed programmes previously using pip so I know my Python/script path is correct in my env variables. However I am seeing the following error FileNotFoundError: [Errno 2] No such…
Richard C
  • 513
  • 1
  • 7
  • 26
18
votes
4 answers

How to see exactly what went wrong in Behave

We recently started using Behave (github link) for BDD of a new python web service. Question Is there any way we can get detailed info about the failure cause as tests fails? They throw AssertionError, but they never show what exactly went wrong.…
JOG
  • 5,590
  • 7
  • 34
  • 54
14
votes
5 answers

How do I skip a test in the behave python BDD framework?

I'm juggling code branches that were partly done a few months ago, with intertwined dependencies. So the easiest way to move forward is to mark failing tests on a particular branch as pending (the rspec way) or to be skipped, and deal with them…
Eric
  • 2,115
  • 2
  • 20
  • 29
12
votes
1 answer

How is data from one Behave step passed to a later step?

Consider a Behave scenario: When some magic number is generated Then the number should be greater than 5 So I have a @when function that produces (say) a random number and I need that number to be present in the @then conditional test. How do I…
Tony Ennis
  • 12,000
  • 7
  • 52
  • 73
12
votes
3 answers

Skip a behave step in the step implementation

Is there a way to tell behave in a step implementation to skip the current step? Something like: @given("bla bla bla") def step(): skip_current_step() The use case is that I want to check if some additional software is installed. If not, I want…
Giacomo d'Antonio
  • 2,215
  • 3
  • 19
  • 23
11
votes
1 answer

KeyError: "'__name__' not in globals" occurs on import from local directory

Directory structure: app\features\login.feature app\features\__init__.py app\features\steps\__init__.py app\features\steps\login.py app\fixtures\__init__.py app\fixtures\fixtures.py app\models\__init__.py app\models\login.py Here is what is inside…
user6499789
11
votes
3 answers

Logging not captured on behave steps

Ok so in my environment.py file I am able to log stuff by: logging.basicConfig(level=logging.DEBUG, filename="example.log") def before_feature(context, feature): logging.info("test logging") but when I am inside the steps file I cannot perform…
nnja
  • 325
  • 3
  • 15
10
votes
0 answers

ERROR:device_event_log_impl.cc(211)] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection:

While running Python code using behave Framework in visual code for selenium Automation logs are: DevTools listening on…
10
votes
9 answers

How to debug Behave BDD scenario using python debugger and Visual studio Code

I use Visual studio code to edit my Behave scenarios and Python steps. I have been able to run my steps using the Visual Studio Code console. I have not been able to configure the python debugger to debug my Python scripts when they are called by…
Tintin_MacFly
  • 141
  • 1
  • 1
  • 5
10
votes
4 answers

Running certain steps once before a scenario outline - Python Behave

As the title suggests, I wish to run some certain configuration / environment setup steps before a scenario outline. I know there is Background to do this for scenarios, but Behave splits a scenario outline into multiple scenarios and thus runs the…
Nightsreach
  • 101
  • 1
  • 1
  • 7
10
votes
3 answers

Define context variables in behave python

Sometimes, you need to define values dynamically, (like datetime now, random strings, random integers, file contents, etc.) and use them across different steps without being explicit or hard-coding the value. So, my question is how could I define…
Federico Castro
  • 119
  • 1
  • 1
  • 5
1
2 3
34 35