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

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 l3str4nge September 30, 2020 15:41
Copy link
Member

@poyea poyea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

.travis.yml Outdated
Comment on lines 16 to 18
- 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/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@dhruvmanila dhruvmanila Sep 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That file was not needed after all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 😁

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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

Copy link
Member Author

@cclauss cclauss Sep 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member Author

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
@cclauss cclauss deleted the Travis-on-a-diet branch September 30, 2020 17:26
@dhruvmanila
Copy link
Member

Thank you! 😁 🎉 👍

stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Travis CI: Remove redundant tests

* fixup! before_script

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request May 13, 2021
* Travis CI: Remove redundant tests

* fixup! before_script

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants