Skip to content
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

Travis CI: Remove redundant tests #2523

Merged
merged 3 commits into from Sep 30, 2020
Merged

Conversation

@cclauss
Copy link
Member

@cclauss cclauss commented Sep 30, 2020

Describe your change:

Many tests (flake8, black, valid filenames, etc.) have migrated to a pre-commit hook #2511 and GitHub Action to run it #2515.

We can now remove those tests from Travis CI so that our automated tests run even faster. @dhruvmanila

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Testing change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
@cclauss cclauss requested review from poyea and mateuszz0000 Sep 30, 2020
@poyea
poyea approved these changes Sep 30, 2020
Copy link
Member

@poyea poyea left a comment

Thanks

.travis.yml Outdated
- pytest --tb=no --no-summary --capture=no project_euler/validate_solutions.py || true # fail fast on wrong solution
- pytest --doctest-modules --durations=10 --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/
Comment on lines 16 to 18

This comment has been minimized.

@dhruvmanila

dhruvmanila Sep 30, 2020
Member

By keeping the testing of Project Euler solutions in script section, Travis won't exit if it fails. If the test is in before_script section, Travis will exit.

This comment has been minimized.

@cclauss

cclauss Sep 30, 2020
Author Member

Why do we run that project_euler/validate_solutions.py thru pytest? It seems like a lot of complexity and overhead.

This comment has been minimized.

@dhruvmanila

dhruvmanila Sep 30, 2020
Member

I did do it without pytest but you mentioned (#2471 (comment)) to include it in as that is already included.

Currently, the algorithm is set in such a way to utilize the pytest.mark.parameterize decorator which calls the function with the arguments as problem_number and expected and at the end uses pytest.fixture to print all the error messages. This can be done without using pytest.

This comment has been minimized.

@dhruvmanila

dhruvmanila Sep 30, 2020
Member

It would be similar to this without pytest: https://github.com/TheAlgorithms/Python/blob/f1d60aca9e8c6cba013e5e5571d180f062bb3452/project_euler/validate_solutions.py

The script will be self-contained and will need no dependencies.

This comment has been minimized.

@cclauss

cclauss Sep 30, 2020
Author Member

It was run automatically by pytest when its name was project_euler/solution_test.py but that stopped being the case when the filename was changed to something that does not obey pytest discovery rules. Let's not mess with it for now because we need to run in || true mode.

This comment has been minimized.

@dhruvmanila

dhruvmanila Sep 30, 2020
Member

Yes, but you mentioned something about failing fast so I changed the filename and used another run for that file and that's why I commented here. If you put the command in script, it's not going to stop the build if it fails. Those options are to suppress all the output from pytest and print our custom output which you can see when it is running.

This comment has been minimized.

@cclauss

cclauss Sep 30, 2020
Author Member

Are you OK with the current state of this PR or is there something that I should change?

This comment has been minimized.

@dhruvmanila

dhruvmanila Sep 30, 2020
Member

I think validate_solutions.py should be in before_script section so that it fails fast when we remove || true

.travis.yml Outdated
install: pip install black flake8
install:
- pip install --upgrade pip setuptools six
- pip install -r requirements_pytest.txt

This comment has been minimized.

@dhruvmanila

dhruvmanila Sep 30, 2020
Member

By convention, those test requirements file are called requirements_dev.txt

This comment has been minimized.

@cclauss

cclauss Sep 30, 2020
Author Member

That file was not needed after all.

This comment has been minimized.

@dhruvmanila

dhruvmanila Sep 30, 2020
Member

It's better to keep a separate file for test requirements for people who actually use it, they can install it directly. We can include all our test requirements in it, but it's up to you. 😁

This comment has been minimized.

@cclauss

cclauss Sep 30, 2020
Author Member

I sense we have three sets of requirements:

  1. requirements.txt for our code's requirements
  2. requirements like black, flake8, isort that are embedded in the pre-commit yaml file
  3. the Travis CI requirements pytest and its plugins

I am reluctant to install requirements that we do not need both on contributors machines and on CI machines.

This comment has been minimized.

@dhruvmanila

dhruvmanila Sep 30, 2020
Member

  • pre-commit doesn't require any installation, it is self-contained
  • test-requirements.txt is only for the user who wants to install all the test tools used in this repository
  • Travis CI won't install packages with test-requirements.txt, we will specify which ones to install

How does this sound?
This means we will have only two requirements file:

  1. Code requirements
  2. Test requirements

This comment has been minimized.

@cclauss

cclauss Sep 30, 2020
Author Member

I believe that we are both good with our current requirements.txt.

That leaves open the question, what should go in the other Test requirements file. If I was running the tests on my machine, I would just type pytest because I do not need coverage and I do not need subtests (whatever that is). So, do we create a separate Test requirements file that only contains -r requirements.txt \n pytest?

I would prefer a called requirements_dev.txt or requirements_test.txt because:

  1. we have no files in this repo that have "-" in their filenames
  2. all the requirements files should appear next to each other in a code listing.

This comment has been minimized.

@dhruvmanila

dhruvmanila Sep 30, 2020
Member

flake8, black, isort, codespell fall in the requirements_dev.txt file as those are the tools used to develop the code as well in terms of linting and formating.

We will tell Travis to install requirements.txt and pytest and its plugins.

pytest-subtests are used when you're having tests for multiple iterations in a given function. By default, one function equals one test for pytest but if the function contains loops that iterate over many values, those will be considered as different tests. pytest will stop if any of those loops fail and exit immediately saying that the function failed. We want to know from all the iterations which ones are going to fail. I don't know if I can explain properly on text so you would have to do some research 😅

This comment has been minimized.

@dhruvmanila

dhruvmanila Sep 30, 2020
Member

This is also one of the benefits of using pipenv for managing your environments. It separates out your common packages and dev packages and you don't have to worry about anything but that's a discussion for another day.

@cclauss cclauss force-pushed the cclauss:Travis-on-a-diet branch from 79754fe to c3439a1 Sep 30, 2020
@cclauss cclauss force-pushed the cclauss:Travis-on-a-diet branch from 46a147b to 12d2c07 Sep 30, 2020
@cclauss cclauss force-pushed the cclauss:Travis-on-a-diet branch from 0645230 to 001040d Sep 30, 2020
github-actions github-actions
@cclauss
Copy link
Member Author

@cclauss cclauss commented Sep 30, 2020

Both Travis runs execute in parallel in approx 3 min 30 sec. Awesome work @dhruvmanila

@cclauss cclauss merged commit ddfa9e4 into TheAlgorithms:master Sep 30, 2020
1 check passed
1 check passed
Travis CI - Pull Request Build Passed
Details
@cclauss cclauss deleted the cclauss:Travis-on-a-diet branch Sep 30, 2020
@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Sep 30, 2020

Thank you! 😁 🎉 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.