Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ab82b98

Browse files
author
Takuya Nishigori
committedNov 23, 2013
Add sample test & settings
1 parent 68669a8 commit ab82b98

File tree

8 files changed

+152
-0
lines changed

8 files changed

+152
-0
lines changed
 

‎README.rst

+37
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,43 @@ TDDBC for Python with Pytest
55

66
.. _Pytest: http://pytest.org/latest-ja/
77

8+
動作確認環境
9+
------------
10+
11+
- Python 2.7.6
12+
- Python 3.3.1
13+
- PyPy 1.9.0
14+
- PyPy 2.2.0
15+
16+
セットアップ
17+
------------
18+
19+
.. code-block:: sh
20+
21+
$ pip install -r requirements.txt
22+
23+
**setup.py** を実行し
24+
25+
.. code-block:: sh
26+
27+
$ python setup.py test
28+
29+
...
30+
31+
# Output sample
32+
======================== test session starts =================================
33+
platform linux2 -- Python 2.7.3[pypy-2.2.0-final] -- pytest-2.4.2
34+
-- ~/.virtualenvs/tddbc_python_pytest_pypy22/bin/python
35+
plugins: cov, xdist
36+
collected 3 items
37+
38+
tests/acme/test_acme.py:28: TestPython.test_be_out_of_question PASSED
39+
tests/acme/test_acme.py:41: TestMontyPython.test_say_name[Monty Python] PASSED
40+
tests/acme/test_acme.py:41: TestMontyPython.test_say_name[John Smith] PASSED
41+
======================== 3 passed in 0.10 seconds ============================
42+
43+
のように正常終了すればOKです
44+
845
ライセンス
946
----------
1047

‎acme/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# package

‎acme/snake.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
from random import randint
4+
5+
6+
class Python(object):
7+
def say(self, greeting=None):
8+
return 'Hiss!' * randint(1, 9)
9+
10+
11+
class MontyPython(Python):
12+
def say(self, greeting):
13+
return 'Hello %s' % greeting

‎requirements.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cov-core==1.7
2+
coverage==3.7
3+
execnet==1.1
4+
py==1.4.17
5+
pytest==2.4.2
6+
pytest-cov==1.6
7+
pytest-xdist==1.9

‎setup.cfg

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[metadata]
2+
license-file = LICENSE
3+
4+
[wheel]
5+
universal = 1
6+
7+
[pytest]
8+
addopts = -rsxX -v
9+
norecursedirs = .git

‎setup.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from setuptools import setup, find_packages
2+
from setuptools.command.test import test as TestCommand
3+
import sys
4+
5+
6+
class PyTest(TestCommand):
7+
def finalize_options(self):
8+
TestCommand.finalize_options(self)
9+
self.test_args = []
10+
self.test_suite = True
11+
12+
def run_tests(self):
13+
#import here, cause outside the eggs aren't loaded
14+
import pytest
15+
errno = pytest.main(self.test_args)
16+
sys.exit(errno)
17+
18+
setup(
19+
name='skeleton_for_pytest',
20+
version='0.0.1',
21+
url='https://github.com/tddbc/python_pytest.git',
22+
author='TDD BaseCamp',
23+
author_email='tddbc@googlegroups.com',
24+
description='The skeleton of py.test for python users',
25+
license='MIT',
26+
packages=find_packages(exclude=['tests']),
27+
tests_require=['pytest'],
28+
cmdclass={'test': PyTest},
29+
classifiers=[
30+
'Intended Audience :: Developers',
31+
'License :: OSI Approved :: MIT License',
32+
'Environment :: Console',
33+
'Operating System :: OS Independent',
34+
'Programming Language :: Python',
35+
'Programming Language :: Python :: 2',
36+
'Programming Language :: Python :: 2.7',
37+
'Programming Language :: Python :: 3',
38+
'Programming Language :: Python :: 3.3',
39+
'Programming Language :: Python :: Implementation :: PyPy',
40+
],
41+
)

‎tests/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# package

‎tests/acme/test_snake.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
サンプルテスト
6+
"""
7+
8+
import re
9+
10+
11+
def pytest_generate_tests(metafunc):
12+
"""
13+
Parametrizing test methods through per-class configuration
14+
http://pytest.org/latest-ja/example/parametrize.html#id5
15+
"""
16+
try:
17+
funcarglist = metafunc.cls.params[metafunc.function.__name__]
18+
except AttributeError:
19+
return
20+
argnames = list(funcarglist[0])
21+
metafunc.parametrize(
22+
argnames,
23+
[[funcargs[name] for name in argnames] for funcargs in funcarglist]
24+
)
25+
26+
27+
class TestPython:
28+
def test_be_out_of_question(self):
29+
from acme.snake import Python
30+
assert re.match(r'^(Hiss\!)+$', Python().say()), 'シャー'
31+
32+
33+
class TestMontyPython:
34+
params = {
35+
'test_say_name': [
36+
dict(name='Monty Python'),
37+
dict(name='John Smith'),
38+
],
39+
}
40+
41+
def test_say_name(self, name):
42+
from acme.snake import MontyPython
43+
assert MontyPython().say(name) == 'Hello ' + name

0 commit comments

Comments
 (0)
Please sign in to comment.