Skip to content

Commit 09cf285

Browse files
authored
tests: add testing w/o 'grpc' installed (googleapis#289)
Closes googleapis#288.
1 parent f4e776e commit 09cf285

16 files changed

+124
-12
lines changed

noxfile.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
nox.options.sessions = [
3434
"unit",
3535
"unit_grpc_gcp",
36+
"unit_wo_grpc",
3637
"cover",
3738
"pytype",
3839
"mypy",
@@ -78,7 +79,7 @@ def blacken(session):
7879
session.run("black", *BLACK_EXCLUDES, *BLACK_PATHS)
7980

8081

81-
def default(session):
82+
def default(session, install_grpc=True):
8283
"""Default unit test session.
8384
8485
This is intended to be run **without** an interpreter set, so
@@ -92,7 +93,10 @@ def default(session):
9293

9394
# Install all test dependencies, then install this package in-place.
9495
session.install("mock", "pytest", "pytest-cov")
95-
session.install("-e", ".[grpc]", "-c", constraints_path)
96+
if install_grpc:
97+
session.install("-e", ".[grpc]", "-c", constraints_path)
98+
else:
99+
session.install("-e", ".", "-c", constraints_path)
96100

97101
pytest_args = [
98102
"python",
@@ -140,6 +144,12 @@ def unit_grpc_gcp(session):
140144
default(session)
141145

142146

147+
@nox.session(python=["3.6", "3.10"])
148+
def unit_wo_grpc(session):
149+
"""Run the unit test suite w/o grpcio installed"""
150+
default(session, install_grpc=False)
151+
152+
143153
@nox.session(python="3.6")
144154
def lint_setup_py(session):
145155
"""Verify that setup.py is valid (including RST check)."""

tests/asyncio/gapic/test_config_async.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
16+
import pytest
17+
18+
try:
19+
import grpc # noqa: F401
20+
except ImportError:
21+
pytest.skip("No GRPC", allow_module_level=True)
22+
1523
from google.api_core import exceptions
1624
from google.api_core.gapic_v1 import config_async
1725

tests/asyncio/gapic/test_method_async.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414

1515
import datetime
1616

17-
from grpc import aio
1817
import mock
1918
import pytest
2019

20+
try:
21+
from grpc import aio
22+
except ImportError:
23+
pytest.skip("No GRPC", allow_module_level=True)
24+
2125
from google.api_core import exceptions
2226
from google.api_core import gapic_v1
2327
from google.api_core import grpc_helpers_async

tests/asyncio/operations_v1/test_operations_async_client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from grpc import aio
1615
import mock
1716
import pytest
1817

19-
from google.api_core import grpc_helpers_async, operations_v1, page_iterator_async
18+
try:
19+
from grpc import aio
20+
except ImportError:
21+
pytest.skip("No GRPC", allow_module_level=True)
22+
23+
from google.api_core import grpc_helpers_async
24+
from google.api_core import operations_v1
25+
from google.api_core import page_iterator_async
2026
from google.longrunning import operations_pb2
2127
from google.protobuf import empty_pb2
2228

tests/asyncio/test_grpc_helpers_async.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import grpc
16-
from grpc import aio
1715
import mock
18-
import pytest
16+
import pytest # noqa: I202
17+
18+
try:
19+
import grpc
20+
from grpc import aio
21+
except ImportError:
22+
grpc = aio = None
23+
24+
25+
if grpc is None:
26+
pytest.skip("No GRPC", allow_module_level=True)
27+
1928

2029
from google.api_core import exceptions
2130
from google.api_core import grpc_helpers_async

tests/asyncio/test_operation_async.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
import mock
1717
import pytest
1818

19+
try:
20+
import grpc # noqa: F401
21+
except ImportError:
22+
pytest.skip("No GRPC", allow_module_level=True)
23+
1924
from google.api_core import exceptions
2025
from google.api_core import operation_async
2126
from google.api_core import operations_v1

tests/unit/gapic/test_client_info.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import pytest
16+
17+
try:
18+
import grpc # noqa: F401
19+
except ImportError:
20+
pytest.skip("No GRPC", allow_module_level=True)
21+
1522

1623
from google.api_core.gapic_v1 import client_info
1724

tests/unit/gapic/test_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import pytest
16+
17+
try:
18+
import grpc # noqa: F401
19+
except ImportError:
20+
pytest.skip("No GRPC", allow_module_level=True)
21+
1522
from google.api_core import exceptions
1623
from google.api_core.gapic_v1 import config
1724

tests/unit/gapic/test_method.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
import datetime
1616

1717
import mock
18+
import pytest
19+
20+
try:
21+
import grpc # noqa: F401
22+
except ImportError:
23+
pytest.skip("No GRPC", allow_module_level=True)
24+
1825

1926
from google.api_core import exceptions
2027
from google.api_core import retry

tests/unit/gapic/test_routing_header.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import pytest
16+
17+
try:
18+
import grpc # noqa: F401
19+
except ImportError:
20+
pytest.skip("No GRPC", allow_module_level=True)
21+
1522

1623
from google.api_core.gapic_v1 import routing_header
1724

0 commit comments

Comments
 (0)