[testing] experiment with a different way of skipping torch-only test modules
Author: stas00
Pull request: yes

This is an experiment. 

I was getting irked by `require_pytorch` followed by yet another `if is_torch_available()` code in many test modules, specifically this part:

```
@require_torch
class BARTModelTest(ModelTesterMixin, unittest.TestCase):
    all_model_classes = (
        (BartModel, BartForConditionalGeneration, BartForSequenceClassification, BartForQuestionAnswering)
        if is_torch_available()
        else ()
    )
    all_generative_model_classes = (BartForConditionalGeneration,) if is_torch_available() else ()
```
`require_torch` doesn't stop the parser from compiling the rest of the code, so the ugly workaround is used.

I tried to find a better solution, to tell the parser to ignore the whole class, since we did tell it to skip it - but didn't succeed. 

But then I noticed that all of the module classes/tests requires pytorch, so I thought why not skip the whole module and not need to repeatedly ask if pytorch is available. That is:

```
if not is_torch_available():
    raise unittest.SkipTest("Skip the whole module as it requires pytorch")
```
and then we can code worry-free, removing any torch checks. We can then alias this whole thing in `testing_utils.py` and call as something like:

```
from testing_utils import skip_module_require_torch
skip_module_require_torch()
```

This PR is such possible solution applied to just one pure pytorch test module. To see it in action, run:

```
 USE_TF=1 pytest tests/test_modeling_bart.py
```

The only drawback is that it doesn't count/report any of the skipped tests, so we get just:

```
collected 0 items / 1 skipped     
```
from pytest. But this will only happen on _tf CI job, so it doesn't matter anyway.

We can do exactly the same for tf-only tests, with its own `skip_module_require_tf`.

As a bonus the test suite will run marginally faster for those pt/tf-only jobs, as it won't need to load/parse any modules - should be a very negligible improvement.

The current way is just fine. But I thought I'd share my experiment in case perhaps it'd lead to a more readable code.

Thank you for reading.

@LysandreJik, @sgugger, @sshleifer, @patrickvonplaten 

Comments:
Great! 

Do you want for us to make this a "model" file first, merge it, see how it feels and then replicate to the rest? Or should I just proceed with the rest?


I think you ca just proceed.

Bummer! If I make it into a function and thus remove `if ...` - isort and flake now complain:
```
$ flake8 tests
tests/test_modeling_bart.py:37:1: E402 module level import not at top of file
tests/test_modeling_bart.py:39:1: E402 module level import not at top of file
tests/test_modeling_bart.py:57:1: E402 module level import not at top of file
$ isort --check-only tests
ERROR: /mnt/nvme1/code/huggingface/transformers-torch-req/tests/module_skip_pytorch.py Imports are incorrectly sorted and/or formatted.
```
so that would require adding #noqa to all the subsequent imports ;( which leaves the code ugly just in a different way.

These tools have so little flexibility. They are supposed to make things better but lead to a much uglier code :(


meh! I call this experiment a failure thanks to `make quality` oppression.

I will just leave the helper I wrote here, in case someone figures out a magical way to solve the ugliness. 

```
def test_module_skip_require_pytorch():
    """
    Call this one on top of test module to skip the whole module if pytorch is not available:
    test_module_skip_require_pytorch()
    """
    if not _torch_available:
        raise unittest.SkipTest("Skip the whole module as it requires pytorch")
```