Skip to content

Conversation

@Borda
Copy link
Collaborator

@Borda Borda commented Feb 11, 2021

What does this PR do?

simplify chaining skip-if in pytests

@pytest.mark.skipif(**skipif_args(min_gpus=2, min_torch="99"))
def test_skip():
    ...

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified
  • Check that target branch and milestone match!

Did you have fun?

Make sure you had fun coding 🙃

@Borda Borda added ci Continuous Integration refactor labels Feb 11, 2021
@Borda Borda added this to the 1.2 milestone Feb 11, 2021
@codecov
Copy link

codecov bot commented Feb 11, 2021

Codecov Report

Merging #5920 (0f658a4) into master (40d5a9d) will decrease coverage by 1%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #5920    +/-   ##
=======================================
- Coverage      93%     92%    -1%     
=======================================
  Files         159     159            
  Lines       11380   11589   +209     
=======================================
+ Hits        10624   10660    +36     
- Misses        756     929   +173     

Base automatically changed from release/1.2-dev to master February 11, 2021 14:32
@Borda Borda force-pushed the tests/skipif branch 2 times, most recently from 4a851db to fef5bde Compare February 11, 2021 19:21
@Borda Borda force-pushed the tests/skipif branch 2 times, most recently from dd98c61 to 47e9a0b Compare February 11, 2021 20:15
@carmocca
Copy link
Contributor

Why not make it @skipIfNoGPUs instead of @pytest.mark.skipif(**_SKIPIF_NO_GPUS)?

@Borda
Copy link
Collaborator Author

Borda commented Feb 11, 2021

Why not make it @skipIfNoGPUs instead of @pytest.mark.skipif(**_SKIPIF_NO_GPUS)?

the main point was about chaining them together and on the same line...

@carmocca
Copy link
Contributor

the main point was about chaining them together and on the same line...

IMO I'd rather have different conditions in different lines, as is usual in other projects

@Borda
Copy link
Collaborator Author

Borda commented Feb 12, 2021

the main point was about chaining them together and on the same line...

IMO I'd rather have different conditions in different lines, as is usual in other projects

so to have grouped under unitest class, since we have for an example test file where each of the included tests has 5 skips if and all the same for all tests so in the skip is most of the code and not clear reading...
cc: @awaelchli @SeanNaren

@Borda
Copy link
Collaborator Author

Borda commented Feb 18, 2021

Ok, so there are let's say three ways to go:

  1. 😄 just to standardize the skip if content so we avoid typos and misalignment of the condition and skip reason so the usage would be just
    @pytest.mark.skipif(**_SKIPIF_PT_LE_1_6)
    @pytest.mark.skipif(**_SKIPIF_NO_APEX)
    @pytest.mark.skipif(**_SKIPIF_NO_GPUS)
    def test_...(...):
        ...
  2. 🚀 chaining the skip conditions so it would be a single line and easier to read
    @pytest.mark.skipif(**(_SKIPIF_PT_LE_1_6 | _SKIPIF_NO_APEX | _SKIPIF_NO_GPUS))
    def test_...(...):
        ...
  3. 🎉 creating custom wrapper with all these cases as argument (which would increase contribution level as a user needs to read/learn this custom parameterization)
    @lightning_mark_skipif(min_pt=1.6, apex=True, min_gpus=2)
    def test_...(...):
        ...
  4. 👀 ready-to-use skipifs
    @gpu_required
    @torch_ge_1_6_required
    @apex_required
    def test():
        ...
  5. 👍 creating custom wrapper with all these cases as argument similar to 3)
    @lightning_mark_skipif(_SKIPIF_PT_LE_1_6, _SKIPIF_NO_APEX, _SKIPIF_NO_GPUS)
    def test_...(...):
        ...

6 @

@lightning_mark_skipif(_SKIPIF_PT_LE_1_6, _SKIPIF_NO_APEX, _SKIPIF_NO_GPUS)
def test_...(...):
    ...

less vote a bit... 1: 😄 2: 🚀 3: 🎉 4: 👀 5: 👍

cc: @PyTorchLightning/core-contributors

@Borda Borda modified the milestones: 1.2, 1.2.x Feb 18, 2021
@Borda Borda marked this pull request as ready for review February 27, 2021 09:03
@Borda
Copy link
Collaborator Author

Borda commented Feb 27, 2021

@tadejsv @SeanNaren @SkafteNicki @akihironitta @rohitgr7 it is not exactly like the promise above as it turned out that the overwriting pytest marks would be tricky and no very sure of any accident unwanted interaction with other pytest marks such as parameterized...

@Borda Borda modified the milestones: 1.2.x, 1.3 Feb 27, 2021
@Borda Borda requested a review from kaushikb11 February 27, 2021 10:17
Copy link
Collaborator

@SkafteNicki SkafteNicki left a comment

Choose a reason for hiding this comment

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

LGTM :]

Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

So why don't we provide the skipif ourselves?

return pytest.mark.skipif(condition=any(conditions), reason=reason)

does it not work?

Borda and others added 3 commits February 27, 2021 17:20
Co-authored-by: Akihiro Nitta <[email protected]>
Co-authored-by: Nicki Skafte <[email protected]>
@Borda Borda requested a review from carmocca February 27, 2021 16:24
@Borda Borda added the ready PRs ready to be merged label Feb 27, 2021
@Lightning-AI Lightning-AI deleted a comment from pep8speaks Feb 27, 2021
Copy link
Contributor

@SeanNaren SeanNaren left a comment

Choose a reason for hiding this comment

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

Nice. Should clean up some of these really stacked decorators finally, so nice work!

@Borda Borda merged commit 58a6d59 into master Mar 1, 2021
@Borda Borda deleted the tests/skipif branch March 1, 2021 12:17
@Borda Borda mentioned this pull request Mar 1, 2021
11 tasks
@tchaton tchaton modified the milestones: 1.3, 1.2.x Mar 2, 2021
kaushikb11 pushed a commit to kaushikb11/pytorch-lightning that referenced this pull request Mar 2, 2021
* skipif + yapf + isort

* tests

* docs

* pp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continuous Integration ready PRs ready to be merged refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants