python-behave

Test coverage tool for Behave test framework

我是研究僧i 提交于 2020-01-02 02:59:06
问题 We are using Behave BDD tool for automating API's. Is there any tool which give code coverage using our behave cases? We tried using coverage module, it didn't work with Behave. 回答1: You can run any module with coverage to see the code usage. In your case should be close to coverage run --source='.' -m behave Tracking code coverage for Aceptace/Integration/Behaviour test will give a high coverage number easily but can lead to the idea that the code are properly tested. Those are for see

How to get the current behave step with Python?

喜夏-厌秋 提交于 2019-12-31 01:01:14
问题 I'm using behave with Python to do my tests. In the step file, I want to get the current step name, because if the test fails, I take a screenshot and rename the file to the step name. Something like this: Given user is logged in When user does something Then something happens And I wanted my step code to be like this: @given('user is logged in') try: # MY CODE HERE except: # GET THE STEP NAME HERE Anyone have an idea how to do this? 回答1: I've done essentially what you are trying to do, take

Naming Cucumber's Data Table

£可爱£侵袭症+ 提交于 2019-12-24 19:53:15
问题 I am creating test cases on forms that could contains over 50 parameters, some of them would show up when a certain set of questions would be answered specifically. The data tables were getting very long so I broke them into multiple data tables, each for a specific section of form. I don't want to add every heading in the step so I want to use the data table's name instead. Instead of: Scenario: . . . When I fill in <title> <first name> <surname> ... |title|first name|surname|...| . . . I

How to run behave-django features in PyCharm?

旧城冷巷雨未停 提交于 2019-12-23 04:53:36
问题 Background I have a Django project ("api") with unittest tests and behave features. Relevant parts of its structure are code/ # i.e. the Django root is not the root of the project manage.py api/ settings.py # and other Django stuff app/ # Django app stuff features/ environment.py steps/ foo.feature virtualenv/ I use behave-django. python manage.py behave works. I use PyCharm. It's configured to use the project's virtualenv. Its Django support is configured thus: Running Django and running

Why isn't behave's documented manual integration with Django working?

非 Y 不嫁゛ 提交于 2019-12-11 05:45:17
问题 I have a Django (1.10.2) project ("theproject") and some behave (0.4.0) features. I've been using behave-django. python manage.py behave works. However, PyCharm (which uses the behave executable rather than a Django management command) doesn't know how to run my features, so I'm attempting to use behave's documented "manual integration" with Django. My entire features/environment.py : import os import django from django.test.runner import DiscoverRunner from django.test.testcases import

Use behave tags to execute only a subcase of such tag

核能气质少年 提交于 2019-12-11 04:39:10
问题 I have the following scenario definition in a sample.feature file, with scenario with two sub-cases using the Examples syntax: @ninja Scenario Outline: this is a sample scenario Given ... And ... And .. When ... Then ... Examples: | param1 | param2 | param3 | | 10 | 4 | 9 | | 20 | 8 | 23 | I can use the tag ninja to execute only that scenario, among all the others defined in the sample.feature file, as follows: $ behave sample.feature --tags=ninja ... Scenario Outline: this is a sample

Handling Exceptions in Python Behave Testing framework

你离开我真会死。 提交于 2019-12-10 03:34:02
问题 I've been thinking about switching from nose to behave for testing (mocha/chai etc have spoiled me). So far so good, but I can't seem to figure out any way of testing for exceptions besides: @then("It throws a KeyError exception") def step_impl(context): try: konfigure.load_env_mapping("baz", context.configs) except KeyError, e: assert (e.message == "No baz configuration found") With nose I can annotate a test with @raises(KeyError) I can't find anything like this in behave (not in the source

Behave: How to import steps from another file?

徘徊边缘 提交于 2019-12-07 12:23:26
问题 I have just started using behave, a Pythonic BDD framework using Gherkin syntax. behave takes a feature, e.g.: Scenario: Calling the metadata API Given A matching server When I call metadata Then metadata response is JSON And response status code is 200 And a steps file, e.g.: ... @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

Skip a behave step in the step implementation

旧城冷巷雨未停 提交于 2019-12-06 23:04:37
问题 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 the complete scenario to be skipped. 回答1: I don't know if you can skip from inside of a step, but you can skip a whole scenario at feature level: def before_feature(context, feature): is_software_installed = some_foo_magic() if not is_software

Run python behave from python instead of command line

廉价感情. 提交于 2019-12-06 02:48:57
问题 Is there any way to run python behave from within python and not via command line? default usage: run behave command in base folder with features/steps desired usage: call a function (or have a certain import) which executes the behave tests in a specified folder 回答1: Found the solution by working through the behave source code: from behave.__main__ import main as behave_main behave_main("path/to/specified/folder") The main method of behave enumerates and processes all paths it finds in its