Skip to content

Start running validate_solutions script for Travis CI #3215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 3 additions & 16 deletions project_euler/validate_solutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)