Skip to content

Commit

Permalink
remove torch as install requirement (#14)
Browse files Browse the repository at this point in the history
* remove torch as install requirement

* make the warning more concise
  • Loading branch information
pmeier authored Apr 19, 2021
1 parent bd98f6b commit 0279a23
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ order_by_type = true
combine_star = true
filter_files = true

known_third_party = ["pytest"]
known_third_party = ["pytest", "_pytest"]
known_first_party = ["torch", "pytest_pytorch"]
known_local_folder = ["tests"]

Expand Down
23 changes: 21 additions & 2 deletions pytest_pytorch/plugin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import re
import unittest.mock
import warnings
from typing import Pattern

from _pytest.unittest import TestCaseFunction, UnitTestCase

from torch.testing._internal.common_device_type import get_device_type_test_bases
from torch.testing._internal.common_utils import TestCase as PyTorchTestCaseTemplate
try:
from torch.testing._internal.common_device_type import get_device_type_test_bases
from torch.testing._internal.common_utils import TestCase as PyTorchTestCaseTemplate

TORCH_AVAILABLE = True
except ImportError:
TORCH_AVAILABLE = False

warnings.warn(
"Disabling the plugin 'pytest-pytorch', because 'torch' could not be imported."
)

def get_device_type_test_bases():
return []

class PyTorchTestCaseTemplate:
pass


class PytestPyTorchInternalError(Exception):
Expand Down Expand Up @@ -93,6 +109,9 @@ def collect(self):


def pytest_pycollect_makeitem(collector, name, obj):
if not TORCH_AVAILABLE:
return None

try:
if (
not issubclass(obj, PyTorchTestCaseTemplate)
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ include_package_data = True
python_requires = >=3.6
install_requires =
pytest
torch

[options.packages.find]
exclude =
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pytorch_channel = nightly
deps =
pytest >= 6
pytest-mock >= 3.1
torch
# The nightlies do not specify numpy as requirement
numpy
commands =
Expand Down

0 comments on commit 0279a23

Please sign in to comment.