Skip to content

Commit 0457d6d

Browse files
Davide Morodavidemoro
Davide Moro
authored andcommitted
update to pytest (make imports more safe in conftest)
1 parent f99308a commit 0457d6d

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

{{cookiecutter.project_slug}}/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pyparsing==2.2.0
2626
PyPOM==1.2.0
2727
pypom-form==0.3.1
2828
pytest-pypom-navigation==0.1.1
29-
pytest==3.0.7
29+
pytest==3.2.3
3030
pytest-bdd==2.18.2
3131
pytest-cov==2.5.1
3232
pytest-html==1.16.0

{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/tests/functional/conftest.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# coding=utf-8
22
"""Login feature tests."""
33

4-
import pytest_bdd
4+
from pytest_bdd import (
5+
given,
6+
when,
7+
then,
8+
)
9+
from pytest_bdd.parsers import (
10+
parse,
11+
)
512

613

7-
@pytest_bdd.given(pytest_bdd.parsers.parse('I am logged in as {user_id}'))
14+
@given(parse('I am logged in as {user_id}'))
815
def username(user_id, navigation):
916
"""Login and returns username for the given user_id """
1017
username, password = navigation.get_credentials(user_id)
@@ -15,9 +22,9 @@ def username(user_id, navigation):
1522
# we need to change step description due to a nasty limitation of pytest-bdd.
1623
# See https://github.com/pytest-dev/pytest-bdd/issues/199
1724

18-
@pytest_bdd.given(pytest_bdd.parsers.parse(
25+
@given(parse(
1926
'[outline] I am on the <page_id> page'))
20-
@pytest_bdd.given(pytest_bdd.parsers.parse(
27+
@given(parse(
2128
'I am on the {page_id} page'))
2229
def loggedin_page_given_outline(page_id, navigation):
2330
"""Logged in fixture"""
@@ -31,31 +38,31 @@ def _check_page_url(page, page_id):
3138
assert page.navigation.get_page_url(page_id) in page.current_url
3239

3340

34-
@pytest_bdd.when(pytest_bdd.parsers.parse(
41+
@when(parse(
3542
'I visit the {page_id} page'))
3643
def visit_page(navigation, page_id):
3744
"""Visit the page."""
3845
navigation.visit_page(page_id)
3946

4047

41-
@pytest_bdd.when(pytest_bdd.parsers.parse(
48+
@when(parse(
4249
'I logout from the application'))
4350
def check_logout_when(navigation):
4451
"""Check the user logout."""
4552
page = navigation.page
4653
page.logout()
4754

4855

49-
@pytest_bdd.then(pytest_bdd.parsers.parse(
56+
@then(parse(
5057
'the page contains text <text>'))
5158
def page_text_check(navigation, text):
5259
page = navigation.page
5360
assert page.has_text(text)
5461

5562

56-
@pytest_bdd.then(pytest_bdd.parsers.parse(
63+
@then(parse(
5764
'I land on the {page_id} page'))
58-
@pytest_bdd.then(pytest_bdd.parsers.parse(
65+
@then(parse(
5966
'I land on the <page_id> page'))
6067
def check_page_url_no_follow(navigation,
6168
page_id):

{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/tests/functional/test_login.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
"""Login feature tests."""
33

44
from functools import partial
5-
import pytest_bdd
5+
from pytest_bdd import (
6+
scenario as bdd_scenario,
7+
then,
8+
)
69

7-
scenario = partial(pytest_bdd.scenario, "functional/login.feature")
10+
scenario = partial(bdd_scenario, "functional/login.feature")
811

912

1013
@scenario("Successful login")
1114
def test_successfull_login():
1215
"""Login."""
1316

1417

15-
@pytest_bdd.then('I am logged in')
18+
@then('I am logged in')
1619
def check_loggedin_then(navigation, username):
1720
"""Assert user is logged in. Implement here your
1821
project related login logics.

0 commit comments

Comments
 (0)