diff --git a/.gitignore b/.gitignore index 9d0329b..72e3942 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ docs/*.png # Testing and coverage results .coverage +pyunit.xml # Build and release directories build diff --git a/.pylintrc b/.pylintrc index db9cb80..6a906d2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -3,12 +3,11 @@ # I0011: Locally disabling %s # W0142: Used * or ** magic # W0511: TODO in comments -disable=I0011,W0142,W0511 +# R0904: Too many public methods +disable=I0011,W0142,W0511,R0904 [REPORTS] -output-format=colorized - reports=no msg-template={msg_id}:{line:3d},{column}:{msg} diff --git a/.travis.yml b/.travis.yml index eeab73c..5af81c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: python python: - 3.3 - 3.4 +env: +- TEST_RUNNER=nose +- TEST_RUNNER=pytest install: - pip install coveralls scrutinizer-ocular script: make ci diff --git a/Makefile b/Makefile index bad6d51..7bb2130 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,12 @@ PYTHON_MAJOR := 3 PYTHON_MINOR := 4 +# Test runner settings +ifndef TEST_RUNNER + # options are: nose, pytest + TEST_RUNNER := nose +endif + # Project settings (automatically detected from files/directories) PROJECT := $(patsubst ./%.sublime-project,%, $(shell find . -type f -name '*.sublime-p*')) PACKAGE := $(patsubst ./%/__init__.py,%, $(shell find . -maxdepth 2 -name '__init__.py')) @@ -46,6 +52,8 @@ PEP257 := $(BIN)/pep257 PYLINT := $(BIN)/pylint PYREVERSE := $(BIN)/pyreverse NOSE := $(BIN)/nosetests +PYTEST := $(BIN)/py.test +COVERAGE := $(BIN)/coverage # Flags for PHONY targets DEPENDS_CI := $(ENV)/.depends-ci @@ -67,7 +75,7 @@ ci: pep8 pep257 test tests .PHONY: env env: .virtualenv $(EGG_INFO) -$(EGG_INFO): Makefile setup.py +$(EGG_INFO): Makefile setup.py requirements.txt $(PYTHON) setup.py develop touch $(EGG_INFO) # flag to indicate package is installed @@ -82,7 +90,7 @@ depends: .depends-ci .depends-dev .PHONY: .depends-ci .depends-ci: env Makefile $(DEPENDS_CI) $(DEPENDS_CI): Makefile - $(PIP) install --upgrade pep8 pep257 nose coverage + $(PIP) install --upgrade pep8 pep257 $(TEST_RUNNER) coverage touch $(DEPENDS_CI) # flag to indicate dependencies are installed .PHONY: .depends-dev @@ -144,13 +152,31 @@ pylint: .depends-dev # Testing #################################################################### .PHONY: test -test: .depends-ci - $(NOSE) --config=.noserc +test: test-$(TEST_RUNNER) .PHONY: tests -tests: .depends-ci +tests: tests-$(TEST_RUNNER) + +# Nosetest commands +.PHONY: test-nose +test-nose: .depends-ci + $(NOSE) --config=.noserc + +.PHONY: tests-nose +tests-nose: .depends-ci TEST_INTEGRATION=1 $(NOSE) --config=.noserc --cover-package=$(PACKAGE) -xv +# Pytest commands +.PHONY: test-py.test +test-pytest: .depends-ci + $(COVERAGE) run --source $(PACKAGE) -m py.test $(PACKAGE) --junitxml=pyunit.xml + $(COVERAGE) report -m + +.PHONY: tests-py.test +tests-pytest: .depends-ci + TEST_INTEGRATION=1 $(COVERAGE) run --source $(PACKAGE) -m py.test $(PACKAGE) --junitxml=pyunit.xml + $(COVERAGE) report -m + # Cleanup #################################################################### .PHONY: clean diff --git a/README.md b/README.md index 6704a11..48864dc 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ To adopt for a new project: * replace `foobar` and `template-python` with your package name * replace `Foobar` with your project name (might be the same as the package) +* set `TEST_RUNNER` in the `Makefile` to your preferred test runner (`nose` or `pytest`) +* remove the `TEST_RUNNER` environment lines in `.travis.yml` * update the links to point to your code repository and badges * change the license diff --git a/foobar/test/test_foobar.py b/foobar/test/test_foobar.py new file mode 100644 index 0000000..bab5991 --- /dev/null +++ b/foobar/test/test_foobar.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +"""Sample test module.""" + +import unittest + + +class TestFooBar(unittest.TestCase): + + """Sample test class.""" + + def test_dependency_import(self): + """Sample test method.""" + try: + import testpackage # pylint: disable=W0612 + assert True + except ImportError: + self.fail() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4066ad9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +testpackage==2.26 diff --git a/setup.py b/setup.py index ba1feba..d493ff9 100644 --- a/setup.py +++ b/setup.py @@ -38,5 +38,5 @@ 'Programming Language :: Python :: 3.3', ], - install_requires=[], + install_requires=open('requirements.txt').readlines(), )