From 6698d837086ca0dd0e39dbca37ca4eef589d57cc Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Sun, 11 Oct 2020 23:18:13 +0530 Subject: [PATCH 1/2] Removed print error_msgs at the end of test: This was done only to reduce the message clutter produced by 60 failing tests. As that is fixed, we can produce the traceback in short form and allow pytest to print the captured error message output at the end of test. --- project_euler/validate_solutions.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/project_euler/validate_solutions.py b/project_euler/validate_solutions.py index 01d70721ea8d..f3ae9fbeffab 100755 --- a/project_euler/validate_solutions.py +++ b/project_euler/validate_solutions.py @@ -15,8 +15,6 @@ with open(PROJECT_EULER_ANSWERS_PATH) as file_handle: PROBLEM_ANSWERS = json.load(file_handle) -error_msgs = [] - def generate_solution_modules( dir_path: pathlib.Path, @@ -48,20 +46,9 @@ def test_project_euler(subtests, problem_number: int, expected: str): answer = str(solution_module.solution()) assert answer == expected, f"Expected {expected} but got {answer}" except (AssertionError, AttributeError, TypeError) as err: - error_msgs.append( - f"problem_{problem_number}/{solution_module.__name__}: {err}" + print( + f"problem_{problem_number:02}/{solution_module.__name__}: {err}" ) - raise # We still want pytest to know that this test failed + raise else: pytest.skip(f"Solution {problem_number} does not exist yet.") - - -# Run this function at the end of all the tests -# https://stackoverflow.com/a/52873379 -@pytest.fixture(scope="session", autouse=True) -def custom_print_message(request): - def print_error_messages(): - if error_msgs: - print("\n" + "\n".join(error_msgs)) - - request.addfinalizer(print_error_messages) From 884fd533794c30aa999bc623b468096c14024945 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Mon, 12 Oct 2020 08:33:36 +0530 Subject: [PATCH 2/2] Start validate_solutions script for Travis CI I am separating out the solution testing and doctest as validating the solutions for the current number of solutions present is taking 2 minutes to run. --- .travis.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index bda0fc31ca5d..ff59af2db34e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,14 @@ jobs: - pytest --doctest-modules --ignore=project_euler/ --durations=10 --cov-report=term-missing:skip-covered --cov=. . - name: Project Euler install: - - pip install pytest-cov pytest-subtests - before_script: - - pytest --tb=no --no-summary --capture=no project_euler/validate_solutions.py || true # fail fast on wrong solution + - pip install pytest-cov script: - pytest --doctest-modules --durations=10 --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/ + - name: Project Euler Solution + install: + - pip install pytest-subtests + script: + - pytest --tb=short project_euler/validate_solutions.py after_success: - scripts/build_directory_md.py 2>&1 | tee DIRECTORY.md notifications: