[fix][tests] fix logic if env variables not present (#55664)
Summary:
Fixes: https://github.com/pytorch/pytorch/issues/55670
Reference: https://github.com/pytorch/pytorch/pull/55522
**Cant Run tests locally without setting the ENV variables**
<details>
```
(pytorch-cuda-dev) kshiteej@qgpu1:~/Pytorch/pytorch_opinfo$ pytest test/test_ops.py
======================================================================= test session starts ========================================================================
platform linux -- Python 3.8.6, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: /home/kshiteej/Pytorch/pytorch_opinfo, configfile: pytest.ini
plugins: hypothesis-5.38.1
collected 0 items
========================================================================= warnings summary =========================================================================
../../.conda/envs/pytorch-cuda-dev/lib/python3.8/site-packages/torch/backends/cudnn/__init__.py:73
/home/kshiteej/.conda/envs/pytorch-cuda-dev/lib/python3.8/site-packages/torch/backends/cudnn/__init__.py:73: UserWarning: PyTorch was compiled without cuDNN/MIOpen support. To use cuDNN/MIOpen, rebuild PyTorch making sure the library is visible to the build system.
warnings.warn(
../../.conda/envs/pytorch-cuda-dev/lib/python3.8/site-packages/torch/testing/_internal/common_nn.py:1195
/home/kshiteej/.conda/envs/pytorch-cuda-dev/lib/python3.8/site-packages/torch/testing/_internal/common_nn.py:1195: UserWarning: Legacy tensor constructor is deprecated. Use: torch.tensor(...) for creating tensors from tensor-like objects; or torch.empty(...) for creating an uninitialized tensor with specific sizes. (Triggered internally at ../torch/csrc/utils/tensor_new.cpp:474.)
random_samples = torch.DoubleTensor(1, 3, 2).uniform_()
-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================================================================= 2 warnings in 2.85s ========================================================================
```
</details>
https://github.com/pytorch/pytorch/blob/c7312f5271b9ce9ac988fffde90818354e5841b8/torch/testing/_internal/common_device_type.py#L479-L486
(When running locally where the environment variable is not set)
The case when the env variable is not present, `os.getenv` returns `''` which is split and we get `['']` for `only_for` and `except_for`.
https://github.com/pytorch/pytorch/blob/c7312f5271b9ce9ac988fffde90818354e5841b8/torch/testing/_internal/common_device_type.py#L496-L497
At this point, we take the branch and skip all the tests.
```python
>>> if [''] and 'cuda' not in ['']:
... print("TRUE")
...
TRUE
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/55664
Reviewed By: albanD
Differential Revision: D27677752
Pulled By: malfet
fbshipit-source-id: 071486e3b6b5113c56f0f956b8d99a5ab24068fe