From 6dc784fe4d33188e4095b1ce6480ff4e746c8eda Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 13 Jul 2020 19:01:51 +0530 Subject: [PATCH 1/4] fix(tests): print traceback from errors --- .travis.yml | 16 ++++++++-------- bench/tests/test_base.py | 6 ++++++ bench/tests/test_init.py | 7 +++++++ bench/tests/test_setup_production.py | 7 +++++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index aa4416c6..0d77579b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,42 +18,42 @@ matrix: - name: "Python 2.7 Basic Setup" python: 2.7 env: TEST=bench - script: python -m unittest -v bench.tests.test_init + script: python -m unittest -v bench.tests.basic - name: "Python 3.6 Basic Setup" python: 3.6 env: TEST=bench - script: python -m unittest -v bench.tests.test_init + script: python -m unittest -v bench.tests.basic - name: "Python 3.7 Basic Setup" python: 3.7 env: TEST=bench - script: python -m unittest -v bench.tests.test_init + script: python -m unittest -v bench.tests.basic - name: "Python 3.8 Production Setup" python: 3.8 env: TEST=bench - script: python -m unittest -v bench.tests.test_setup_production + script: python -m unittest -v bench.tests.production_setup - name: "Python 2.7 Production Setup" python: 2.7 env: TEST=bench - script: python -m unittest -v bench.tests.test_setup_production + script: python -m unittest -v bench.tests.production_setup - name: "Python 3.6 Production Setup" python: 3.6 env: TEST=bench - script: python -m unittest -v bench.tests.test_setup_production + script: python -m unittest -v bench.tests.production_setup - name: "Python 3.7 Production Setup" python: 3.7 env: TEST=bench - script: python -m unittest -v bench.tests.test_setup_production + script: python -m unittest -v bench.tests.production_setup - name: "Python 3.8 Production Setup" python: 3.8 env: TEST=bench - script: python -m unittest -v bench.tests.test_setup_production + script: python -m unittest -v bench.tests.production_setup - name: "Python 3.6 Easy Install" python: 3.6 diff --git a/bench/tests/test_base.py b/bench/tests/test_base.py index 44dc131d..5807ec44 100644 --- a/bench/tests/test_base.py +++ b/bench/tests/test_base.py @@ -102,3 +102,9 @@ class TestBenchBase(unittest.TestCase): if os.environ.get("CI"): return not subprocess.call(["sudo", "test", "-f", path]) return os.path.isfile(path) + + def get_traceback(self): + exc_type, exc_value, exc_tb = sys.exc_info() + trace_list = traceback.format_exception(exc_type, exc_value, exc_tb) + body = "".join(str(t) for t in trace_list) + return body diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index cf92d630..07b0f96a 100755 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -34,6 +34,13 @@ class TestBenchInit(TestBenchBase): self.assert_config(bench_name) + def basic(self): + try: + self.test_init() + except Exception: + print(self.get_traceback()) + + def test_multiple_benches(self): for bench_name in ("test-bench-1", "test-bench-2"): self.init_bench(bench_name) diff --git a/bench/tests/test_setup_production.py b/bench/tests/test_setup_production.py index e0a60b17..9e9f0bd2 100644 --- a/bench/tests/test_setup_production.py +++ b/bench/tests/test_setup_production.py @@ -33,6 +33,13 @@ class TestSetupProduction(TestBenchBase): bench.utils.exec_cmd("sudo bench disable-production", cwd=bench_path) + def production_setup(self): + try: + self.test_setup_production() + except Exception: + print(self.get_traceback()) + + def assert_nginx_config(self, bench_name): conf_src = os.path.join(os.path.abspath(self.benches_path), bench_name, 'config', 'nginx.conf') conf_dest = "/etc/nginx/conf.d/{bench_name}.conf".format(bench_name=bench_name) From 87bc347b5cc683b13a9a15549e379f4e045e79df Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 13 Jul 2020 19:02:30 +0530 Subject: [PATCH 2/4] style: sorted imports + trailing spaces --- bench/tests/test_base.py | 10 +++++----- bench/tests/test_init.py | 4 ++-- bench/tests/test_setup_production.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bench/tests/test_base.py b/bench/tests/test_base.py index 5807ec44..73cc90f5 100644 --- a/bench/tests/test_base.py +++ b/bench/tests/test_base.py @@ -1,19 +1,19 @@ # imports - standard imports +import getpass import json import os import shutil import subprocess import sys +import traceback import unittest -import getpass - -# imports - module imports -import bench -import bench.utils # imports - third party imports from six import PY2 +# imports - module imports +import bench +import bench.utils if PY2: FRAPPE_BRANCH = "version-12" diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index 07b0f96a..69d49a45 100755 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -11,7 +11,7 @@ import git import bench import bench.utils from bench.release import get_bumped_version -from bench.tests.test_base import TestBenchBase, FRAPPE_BRANCH +from bench.tests.test_base import FRAPPE_BRANCH, TestBenchBase class TestBenchInit(TestBenchBase): @@ -155,4 +155,4 @@ class TestBenchInit(TestBenchBase): if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() diff --git a/bench/tests/test_setup_production.py b/bench/tests/test_setup_production.py index 9e9f0bd2..272db54d 100644 --- a/bench/tests/test_setup_production.py +++ b/bench/tests/test_setup_production.py @@ -176,4 +176,4 @@ class TestSetupProduction(TestBenchBase): if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() From 939d3d5c6d1dd6f2391ef0bb3dfe3344f3dd6fb8 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 13 Jul 2020 19:12:23 +0530 Subject: [PATCH 3/4] chore: run specified test alone --- .travis.yml | 16 ++++++++-------- bench/tests/test_setup_production.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0d77579b..4ad7e0f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,42 +18,42 @@ matrix: - name: "Python 2.7 Basic Setup" python: 2.7 env: TEST=bench - script: python -m unittest -v bench.tests.basic + script: python bench/tests/test_init.py TestBenchInit.basic - name: "Python 3.6 Basic Setup" python: 3.6 env: TEST=bench - script: python -m unittest -v bench.tests.basic + script: python bench/tests/test_init.py TestBenchInit.basic - name: "Python 3.7 Basic Setup" python: 3.7 env: TEST=bench - script: python -m unittest -v bench.tests.basic + script: python bench/tests/test_init.py TestBenchInit.basic - name: "Python 3.8 Production Setup" python: 3.8 env: TEST=bench - script: python -m unittest -v bench.tests.production_setup + script: python bench/tests/test_setup_production.py TestSetupProduction.production - name: "Python 2.7 Production Setup" python: 2.7 env: TEST=bench - script: python -m unittest -v bench.tests.production_setup + script: python bench/tests/test_setup_production.py TestSetupProduction.production - name: "Python 3.6 Production Setup" python: 3.6 env: TEST=bench - script: python -m unittest -v bench.tests.production_setup + script: python bench/tests/test_setup_production.py TestSetupProduction.production - name: "Python 3.7 Production Setup" python: 3.7 env: TEST=bench - script: python -m unittest -v bench.tests.production_setup + script: python bench/tests/test_setup_production.py TestSetupProduction.production - name: "Python 3.8 Production Setup" python: 3.8 env: TEST=bench - script: python -m unittest -v bench.tests.production_setup + script: python bench/tests/test_setup_production.py TestSetupProduction.production - name: "Python 3.6 Easy Install" python: 3.6 diff --git a/bench/tests/test_setup_production.py b/bench/tests/test_setup_production.py index 272db54d..f371e454 100644 --- a/bench/tests/test_setup_production.py +++ b/bench/tests/test_setup_production.py @@ -33,7 +33,7 @@ class TestSetupProduction(TestBenchBase): bench.utils.exec_cmd("sudo bench disable-production", cwd=bench_path) - def production_setup(self): + def production(self): try: self.test_setup_production() except Exception: From 3ea66343284e45b72bbe1e2558f7cc6baadc274c Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 5 Aug 2020 13:59:00 +0530 Subject: [PATCH 4/4] fix: run test builds for py2.7 and py3.7 --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4ad7e0f6..295e057d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,6 +55,16 @@ matrix: env: TEST=bench script: python bench/tests/test_setup_production.py TestSetupProduction.production + - name: "Python 2.7 Tests" + python: 2.7 + env: TEST=bench + script: python -m unittest -v bench.tests.test_init + + - name: "Python 3.7 Tests" + python: 3.7 + env: TEST=bench + script: python -m unittest -v bench.tests.test_init + - name: "Python 3.6 Easy Install" python: 3.6 env: TEST=easy_install