From: Oleg Broytman Date: Sun, 11 Sep 2016 19:20:28 +0000 (+0300) Subject: Use pytest for testing X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=fe3b3f07b04313b539ea8894dca05ba6e6eb60aa;p=cookiecutter.git Use pytest for testing --- diff --git a/project_template/tests/Makefile b/project_template/tests/Makefile index b990065..0c6125e 100644 --- a/project_template/tests/Makefile +++ b/project_template/tests/Makefile @@ -1,4 +1,4 @@ .PHONY: all all: - ./run_all.py + pytest diff --git a/project_template/tests/__init__.py b/project_template/tests/__init__.py deleted file mode 100644 index 3c09ede..0000000 --- a/project_template/tests/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ - -import unittest - -__all__ = ['TestCase', 'main'] - - -class TestCase(unittest.TestCase): - def setUp(self): - pass - - def tearDown(self): - pass - - -def main(): - try: - unittest.main(testRunner=unittest.TextTestRunner()) - except SystemExit, msg: - result = msg.args[0] - else: - result = 0 - raise SystemExit(result) diff --git a/project_template/tests/run_all.py b/project_template/tests/run_all.py deleted file mode 100755 index 2e217bf..0000000 --- a/project_template/tests/run_all.py +++ /dev/null @@ -1,38 +0,0 @@ -#! /usr/bin/env python - - -import os -import sys -import subprocess - - -def isexecutable(filename): - infile = open(filename, 'r') - magic = infile.read(2) - infile.close() - return magic == "#!" - - -def collect_tests(): - tests = [] - for dirpath, dirs, files in os.walk("tests"): - tests.extend( - [os.path.join(dirpath, filename) for filename in files - if filename.startswith("test") and filename.endswith(".py") - ]) - return [test[:-3].replace(os.sep, '.') for test in tests - if isexecutable(test)] - - -def main(): - os.chdir(os.path.join(os.path.dirname(sys.argv[0]), os.pardir)) - tests = collect_tests() - - os.environ["PYTHONPATH"] = os.curdir - - for test in sorted(tests): - print test - subprocess.call((sys.executable, '-m', test)) - -if __name__ == '__main__': - main() diff --git a/project_template/tests/test_test.py b/project_template/tests/test_test.py index 1a34012..d4b9c59 100755 --- a/project_template/tests/test_test.py +++ b/project_template/tests/test_test.py @@ -1,14 +1,6 @@ #! /usr/bin/env python -import unittest -from tests import main - - -class TestTest(unittest.TestCase): +class TestTest(object): def test_test(self): - self.assertEqual() - - -if __name__ == "__main__": - main() + assert True