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

Migrate pytest configurations to pyproject.toml #725

Merged
merged 3 commits into from
Dec 14, 2020
Merged

Conversation

seisman
Copy link
Member

@seisman seisman commented Dec 11, 2020

Description of proposed changes

This PR moves pytest configurations (actually some pytest options) to pyproject.toml.

Motivation:

Let's say I'm working on the Figure.text() function, and I want to run the pygmt/tests/test_text.py locally to make sure that my changes work. I should use the long command:

pytest --verbose --mpl --mpl-results-path=results --doctest-modules pygmt/tests/test_text.py

but sometimes (very often) I just run pytest without any options:

pytest pygmt/tests/test_text.py

As I don't give the --verbose --mpl --mpl-results-path=results --doctest-modules option, pytest doesn't do the image comparisons at all, and it reports that all tests pass. It often confuses me a lot before I realize that I missed the necessary options.

With this PR, pytest reads configurations from pyproject.toml and adds the necessary options automatically. So that the short command pytest pygmt/tests/test_text.py always do the image comparisons and doctests.

Pros:

  1. Shorter and more intuitive command to run tests in one or a few files

Cons:

  1. pyproject.toml support needs pytest v6.0 (released on 2020-07-28). Note that Anaconda Python 3.7 ships pytest 6.1.1, while Anaconda Python 3.6 ships pytest 5.4.3. But we have dropped Python 3.6 recently. So it won't be a big issue, especially that pytest is only used when developing pygmt.
  2. To generate baseline images, we still need to run pytest --mpl-generate-path=baseline pygmt/tests/test_text.py, and it gives an warning UserWarning: Ignoring --mpl-result-path since --mpl-generate-path is set. The warning is acceptable to me, and we are also trying our best to avoid storing baseline images in the repository. So I think it won't be a big issue.

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

Notes

  • You can write /format in the first line of a comment to lint the code automatically

@seisman seisman added this to the 0.3.0 milestone Dec 11, 2020
@seisman seisman added the maintenance Boring but important stuff for the core devs label Dec 11, 2020
@seisman seisman requested a review from a team December 11, 2020 01:47
@seisman
Copy link
Member Author

seisman commented Dec 13, 2020

Ping @GenericMappingTools/python for a review.

Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

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

Looks good, this will definitely make it easier for new developers! (Personally though, I prefer typing things out in full so that I know what's running 😆). Ideally there should be a way to disable the configured addopts temporarily, but it's not a major problem.

As an aside, we'll need to revisit the make test command to be Windows compatible at some point, I recall Leo mentioning using tox or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants