Merge pull request #1 from olegpidsadnyi/initial-tests

Initial tests
This commit is contained in:
olegpidsadnyi 2013-04-03 01:30:32 -07:00
commit 21bf58b8c8
7 changed files with 114 additions and 4 deletions

7
.gitignore vendored
View File

@ -34,4 +34,11 @@ nosetests.xml
.project
.pydevproject
# Sublime
/*.sublime-*
# virtualenv
/.Python
/lib
/include
/src

8
.travis.yml Normal file
View File

@ -0,0 +1,8 @@
language: python
python:
- "2.6"
- "2.7"
# command to install dependencies
install: "python setup.py develop"
# # command to run tests
script: python setup.py test

View File

@ -25,4 +25,4 @@ class Library(object):
# Collect when and then steps
for attr in vars(module).itervalues():
if getattr(attr, '__step_type__', None):
self.step[attr.__step_name__] = attr
self.steps[attr.__step_name__] = attr

View File

@ -19,6 +19,10 @@ from pytest_bdd.feature import Feature
from pytest_bdd.types import THEN
class ScenarioNotFound(Exception):
"""Scenario Not Found"""
def scenario(feature_name, scenario_name):
"""Scenario."""
frame = inspect.stack()[1]
@ -28,7 +32,10 @@ def scenario(feature_name, scenario_name):
def _scenario(request):
library = Library(request, module)
feature = Feature.get_feature(feature_path)
scenario = feature.scenarios[scenario_name]
try:
scenario = feature.scenarios[scenario_name]
except KeyError:
raise ScenarioNotFound('Scenario "{0}" in feature "{1}" is not found'.format(scenario_name, feature_name))
# Evaluate given steps (can have side effects)
for given in scenario.given:
@ -55,4 +62,3 @@ def _execute_step(request, func):
result = func(**kwargs)
if func.__step_type__ == THEN:
assert result or result is None

View File

@ -0,0 +1,3 @@
"""Configuration for pytest runner."""
pytest_plugins = "pytester"

View File

@ -0,0 +1,68 @@
"""Tests for pytest-bdd-splinter subplugin."""
def test_pytest_scenario(testdir):
testdir.maketxtfile(**{'some_feature': """
Scenario: Test some feature
Given I have an event
And the merchant has a backoffice user
When I am at the event dashboard page
And I click the copy event button
Then I should not see an error message
And the event name should start with Copy of
"""})
testdir.makepyfile("""
import pytest
from pytest_bdd import scenario, given, when, then
test_scenario = scenario('some_feature.txt', 'Test some feature')
@given('I have an event')
@pytest.fixture
def event():
return object()
@given('the merchant has a backoffice user')
@pytest.fixture
def merchant_user():
return 'some user'
@pytest.fixture
def browser():
return object()
@pytest.fixture
def backoffice_browser(browser):
return object()
@when('I am at the event dashboard page')
def i_go_to_event(event, backoffice_browser):
pass
@when('I click the copy event button')
def click_copy_event(event, browser):
pass
@then('I should not see an error message')
def i_should_not_see_an_error(browser):
assert True
@then('the event name should start with Copy of')
def event_name_should_start_with_copy_of(browser):
assert True
""")
result = testdir.runpytest("-v")
result.stdout.fnmatch_lines([
"*test_scenario*PASS*",
])

View File

@ -1,6 +1,22 @@
#!/usr/bin/env python
import os
from setuptools import setup, find_packages
from setuptools import setup, Command, find_packages
class PyTest(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import sys
import subprocess
errno = subprocess.call([sys.executable, '-m', 'pytest'])
raise SystemExit(errno)
packages = find_packages(os.path.dirname(os.path.abspath(__file__)))
@ -8,8 +24,10 @@ setup(
name='pytest-bdd',
description='BDD for pytest',
version='0.1',
cmdclass={'test': PyTest},
install_requires=[
'pytest',
],
tests_require=['mock'],
packages=packages,
)