diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e798535..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: python -python: - - 2.7 - - 3.3 - - 3.4 - - 3.5 - - pypy - -install: - - pip install tox tox-travis - - pip install coverage coveralls - -script: - - tox -r diff --git a/README.rst b/README.rst index e5ae659..a212547 100644 --- a/README.rst +++ b/README.rst @@ -9,40 +9,64 @@ TDDBC for Python with Pytest 動作確認環境 ============ -- Python 2.7.6 -- Python 3.3.1 -- PyPy 1.9.0 -- PyPy 2.2.0 +- Python 3.8.5 +- pytest 6.2.4 + +※Python2は2020年1月にサポート終了(EOL)していますので、Python3をご利用ください。 セットアップ ============ +以下のように実行して、環境を構築してください。 + .. code-block:: sh - $ pip install -r requirements.txt + $ git clone https://github.com/yattom/python_pytest.git + $ cd python_pytest + $ pip3 install -r requirements.txt -**setup.py** を実行し +テストを実行するには **pytest** コマンドを使います。 .. code-block:: sh - $ python setup.py test - + $ pytest ... - # Output sample - ======================== test session starts ================================= - platform linux2 -- Python 2.7.3[pypy-2.2.0-final] -- pytest-2.4.2 - -- ~/.virtualenvs/tddbc_python_pytest_pypy22/bin/python - plugins: cov, xdist - collected 3 items + ============================= test session starts ============================== + platform linux -- Python 3.8.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 + rootdir: /root/work/python_pytest + plugins: cov-2.11.1 + collected 5 items - tests/acme/test_acme.py:28: TestPython.test_be_out_of_question PASSED - tests/acme/test_acme.py:41: TestMontyPython.test_say_name[Monty Python] PASSED - tests/acme/test_acme.py:41: TestMontyPython.test_say_name[John Smith] PASSED - ======================== 3 passed in 0.10 seconds ============================ + tests/acme/test_snake.py ..... [100%] + + ============================== 5 passed in 0.04s =============================== のように正常終了すればOKです +実行したテストを1つずつ表示するには **-v** オプションを使います。 + +.. code-block:: sh + + $ pytest -v + ... + # Output sample + ============================= test session starts ============================== + platform linux -- Python 3.8.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- /root/work/python_pytest/.venv/bin/python3 + cachedir: .pytest_cache + rootdir: /root/work/python_pytest + plugins: cov-2.11.1 + collected 5 items + + tests/acme/test_snake.py::test_python_hisses PASSED [ 20%] + tests/acme/test_snake.py::TestMontyPython::test_say_name_guido PASSED [ 40%] + tests/acme/test_snake.py::TestMontyPython::test_say_name_kent PASSED [ 60%] + tests/acme/test_snake.py::TestMontyPython::test_say_name[Terry-Hello Terry] PASSED [ 80%] + tests/acme/test_snake.py::TestMontyPython::test_say_name[John-Hello John] PASSED [100%] + + ============================== 5 passed in 0.05s =============================== + + ライセンス ========== diff --git a/requirements.txt b/requirements.txt index ab0619b..d79fbe7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,3 @@ -cov-core==1.15.0 -coverage==4.4.1 -execnet==1.4.1 -py==1.4.34 -pytest==3.1.3 -pytest-cov==2.5.1 -pytest-xdist==1.18.0 -tox==2.7.0 -virtualenv==15.1.0 +-e . +pytest-cov==2.11.1 +pytest==6.2.4 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 937a34d..0000000 --- a/setup.cfg +++ /dev/null @@ -1,9 +0,0 @@ -[metadata] -license-file = LICENSE - -[wheel] -universal = 1 - -[tool:pytest] -addopts = -rsxX -v tests acme -norecursedirs = .git diff --git a/setup.py b/setup.py index 4687786..d13886d 100644 --- a/setup.py +++ b/setup.py @@ -1,19 +1,4 @@ from setuptools import setup, find_packages -from setuptools.command.test import test as TestCommand -import sys - - -class PyTest(TestCommand): - def finalize_options(self): - TestCommand.finalize_options(self) - self.test_args = [] - self.test_suite = True - - def run_tests(self): - #import here, cause outside the eggs aren't loaded - import pytest - errno = pytest.main(self.test_args) - sys.exit(errno) setup( name='skeleton_for_pytest', @@ -25,7 +10,6 @@ def run_tests(self): license='MIT', packages=find_packages(exclude=['tests']), tests_require=['pytest'], - cmdclass={'test': PyTest}, classifiers=[ 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', diff --git a/tests/acme/test_snake.py b/tests/acme/test_snake.py index 33a20d8..dbd49d6 100644 --- a/tests/acme/test_snake.py +++ b/tests/acme/test_snake.py @@ -5,39 +5,37 @@ サンプルテスト """ -import re - - -def pytest_generate_tests(metafunc): - """ - Parametrizing test methods through per-class configuration - http://pytest.org/latest-ja/example/parametrize.html#id5 - """ - try: - funcarglist = metafunc.cls.params[metafunc.function.__name__] - except AttributeError: - return - argnames = list(funcarglist[0]) - metafunc.parametrize( - argnames, - [[funcargs[name] for name in argnames] for funcargs in funcarglist] - ) +import pytest +from acme.snake import Python, MontyPython + +def test_python_hisses(): + sut = Python() + actual = sut.say() + assert 'Hello' not in actual, 'PythonはHelloと言わない' -class TestPython: - def test_be_out_of_question(self): - from acme.snake import Python - assert re.match(r'^(Hiss\!)+$', Python().say()), 'シャー' + +@pytest.fixture +def monty_python(): + return MontyPython() class TestMontyPython: - params = { - 'test_say_name': [ - dict(name='Monty Python'), - dict(name='John Smith'), - ], - } - - def test_say_name(self, name): - from acme.snake import MontyPython - assert MontyPython().say(name) == 'Hello ' + name + def test_say_name_guido(self, monty_python): + actual = monty_python.say('Guido') + assert actual == 'Hello Guido' + + def test_say_name_kent(self, monty_python): + actual = monty_python.say('Kent') + assert actual == 'Hello Kent' + + @pytest.mark.parametrize( + "name, expected", + [ + ('Terry', 'Hello Terry'), + ('John', 'Hello John'), + ] + ) + def test_say_name(self, monty_python, name, expected): + actual = monty_python.say(name) + assert actual == expected diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 2d3a29c..0000000 --- a/tox.ini +++ /dev/null @@ -1,13 +0,0 @@ -[tox] -skipsdist = True -envlist = - py27, - py33, - py34, - py35 - -[testenv] -deps= - -r{toxinidir}/requirements.txt -commands= - python setup.py test