Skip to content

update to pytest 3.2.3 (make imports more safe in conftest) #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion {{cookiecutter.project_slug}}/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pyparsing==2.2.0
PyPOM==1.2.0
pypom-form==0.3.1
pytest-pypom-navigation==0.1.1
pytest==3.0.7
pytest==3.2.3
pytest-bdd==2.18.2
pytest-cov==2.5.1
pytest-html==1.16.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# coding=utf-8
"""Login feature tests."""

import pytest_bdd
from pytest_bdd import (
given,
when,
then,
)
from pytest_bdd.parsers import (
parse,
)


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

@pytest_bdd.given(pytest_bdd.parsers.parse(
@given(parse(
'[outline] I am on the <page_id> page'))
@pytest_bdd.given(pytest_bdd.parsers.parse(
@given(parse(
'I am on the {page_id} page'))
def loggedin_page_given_outline(page_id, navigation):
"""Logged in fixture"""
Expand All @@ -31,31 +38,31 @@ def _check_page_url(page, page_id):
assert page.navigation.get_page_url(page_id) in page.current_url


@pytest_bdd.when(pytest_bdd.parsers.parse(
@when(parse(
'I visit the {page_id} page'))
def visit_page(navigation, page_id):
"""Visit the page."""
navigation.visit_page(page_id)


@pytest_bdd.when(pytest_bdd.parsers.parse(
@when(parse(
'I logout from the application'))
def check_logout_when(navigation):
"""Check the user logout."""
page = navigation.page
page.logout()


@pytest_bdd.then(pytest_bdd.parsers.parse(
@then(parse(
'the page contains text <text>'))
def page_text_check(navigation, text):
page = navigation.page
assert page.has_text(text)


@pytest_bdd.then(pytest_bdd.parsers.parse(
@then(parse(
'I land on the {page_id} page'))
@pytest_bdd.then(pytest_bdd.parsers.parse(
@then(parse(
'I land on the <page_id> page'))
def check_page_url_no_follow(navigation,
page_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
"""Login feature tests."""

from functools import partial
import pytest_bdd
from pytest_bdd import (
scenario as bdd_scenario,
then,
)

scenario = partial(pytest_bdd.scenario, "functional/login.feature")
scenario = partial(bdd_scenario, "functional/login.feature")


@scenario("Successful login")
def test_successfull_login():
"""Login."""


@pytest_bdd.then('I am logged in')
@then('I am logged in')
def check_loggedin_then(navigation, username):
"""Assert user is logged in. Implement here your
project related login logics.
Expand Down