Skip to content

Commit

Permalink
Add --create-external-resources pytest flag to opt into running end-t…
Browse files Browse the repository at this point in the history
…o-end tests (#324)
  • Loading branch information
jacobtomlinson committed Dec 6, 2021
1 parent 09c72a2 commit 4d2d9ea
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dask_cloudprovider/aws/tests/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,23 @@ async def skip_without_credentials():


@pytest.fixture
@pytest.mark.external
async def cluster():
await skip_without_credentials()
async with EC2Cluster(asynchronous=True) as cluster:
yield cluster


@pytest.fixture
@pytest.mark.external
async def cluster_sync():
await skip_without_credentials()
cluster = EC2Cluster()
yield cluster


@pytest.fixture
@pytest.mark.external
async def cluster_rapids():
await skip_without_credentials()
async with EC2Cluster(
Expand All @@ -54,6 +57,7 @@ async def cluster_rapids():


@pytest.fixture
@pytest.mark.external
async def cluster_rapids_packer():
await skip_without_credentials()
async with EC2Cluster(
Expand All @@ -70,6 +74,7 @@ async def cluster_rapids_packer():


@pytest.fixture
@pytest.mark.external
async def cluster_packer():
await skip_without_credentials()
async with EC2Cluster(
Expand All @@ -86,6 +91,7 @@ async def ec2_client():


@pytest.mark.asyncio
@pytest.mark.external
async def test_init():
cluster = EC2Cluster(asynchronous=True)
assert cluster.status == Status.created
Expand Down
4 changes: 4 additions & 0 deletions dask_cloudprovider/azure/tests/test_azurevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async def get_config():

@pytest.mark.asyncio
@skip_without_credentials
@pytest.mark.external
async def test_init():
cluster = AzureVMCluster(asynchronous=True)
assert cluster.status == Status.created
Expand All @@ -56,6 +57,7 @@ async def test_init():
@pytest.mark.asyncio
@pytest.mark.timeout(1200)
@skip_without_credentials
@pytest.mark.external
async def test_create_cluster():
async with AzureVMCluster(asynchronous=True) as cluster:
assert cluster.status == Status.running
Expand All @@ -75,6 +77,7 @@ def inc(x):
@pytest.mark.asyncio
@pytest.mark.timeout(1200)
@skip_without_credentials
@pytest.mark.external
async def test_create_cluster_sync():

with AzureVMCluster() as cluster:
Expand All @@ -92,6 +95,7 @@ def inc(x):
@pytest.mark.asyncio
@pytest.mark.timeout(1200)
@skip_without_credentials
@pytest.mark.external
async def test_create_rapids_cluster_sync():

with AzureVMCluster(
Expand Down
28 changes: 28 additions & 0 deletions dask_cloudprovider/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest


def pytest_addoption(parser):
parser.addoption(
"--create-external-resources",
action="store_true",
default=False,
help="Run tests that create external resources.",
)


def pytest_configure(config):
config.addinivalue_line(
"markers", "external: mark test as creates external resources"
)


def pytest_collection_modifyitems(config, items):
if config.getoption("--create-external-resources"):
# --runslow given in cli: do not skip slow tests
return
skip_slow = pytest.mark.skip(
reason="need --create-external-resources option to run"
)
for item in items:
if "external" in item.keywords:
item.add_marker(skip_slow)
3 changes: 3 additions & 0 deletions dask_cloudprovider/digitalocean/tests/test_droplet.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,23 @@ async def config():


@pytest.fixture
@pytest.mark.external
async def cluster(config):
await skip_without_credentials(config)
async with DropletCluster(asynchronous=True) as cluster:
yield cluster


@pytest.mark.asyncio
@pytest.mark.external
async def test_init():
cluster = DropletCluster(asynchronous=True)
assert cluster.status == Status.created


@pytest.mark.asyncio
@pytest.mark.timeout(600)
@pytest.mark.external
async def test_create_cluster(cluster):
assert cluster.status == Status.running

Expand Down
4 changes: 4 additions & 0 deletions dask_cloudprovider/gcp/tests/test_gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async def test_get_cloud_init():

@pytest.mark.asyncio
@pytest.mark.timeout(1200)
@pytest.mark.external
async def test_create_cluster():
skip_without_credentials()

Expand Down Expand Up @@ -93,6 +94,7 @@ def check_env():

@pytest.mark.asyncio
@pytest.mark.timeout(1200)
@pytest.mark.external
async def test_create_cluster_sync():
skip_without_credentials()

Expand All @@ -107,6 +109,7 @@ def inc(x):

@pytest.mark.asyncio
@pytest.mark.timeout(1200)
@pytest.mark.external
async def test_create_rapids_cluster():
skip_without_credentials()

Expand Down Expand Up @@ -149,6 +152,7 @@ def gpu_mem():


@pytest.mark.timeout(1200)
@pytest.mark.external
def test_create_rapids_cluster_sync():
skip_without_credentials()
cluster = GCPCluster(
Expand Down
1 change: 1 addition & 0 deletions dask_cloudprovider/hetzner/tests/test_vserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async def config():


@pytest.fixture
@pytest.mark.external
async def cluster(config):
await skip_without_credentials(config)
async with HetznerCluster(asynchronous=True) as cluster:
Expand Down
1 change: 1 addition & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ this code.
:hidden:
:caption: Developer

testing.rst
releasing.rst
41 changes: 41 additions & 0 deletions doc/source/testing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Testing
=======

Tests in ``dask-cloudprovider`` and written and run using ``pytest``.

To set up your testing environment run:

.. code-block:: bash
pip install -r requirements_test.txt
To run tests run ``pytest`` from the root directory

.. code-block:: bash
pytest
You may notice that many tests will be skipped. This is because those tests create external resources on cloud providers. You can set those tests to run with the
``--create-external-resources`` flag.

.. warning::

Running tests that create external resources are slow and will cost a small amount of credit on each cloud provider.

.. code-block:: bash
pytest -rs --create-external-resources
It is also helpful to set the ``-rs`` flag here because tests may also skip if you do not have appropriate credentials to create those external resources.
If this is the case the skip reason will contain instructions on how to set up those credentials. For example

.. code-block::
SKIPPED [1] dask_cloudprovider/azure/tests/test_azurevm.py:49:
You must configure your Azure resource group and vnet to run this test.
$ export DASK_CLOUDPROVIDER__AZURE__LOCATION="<LOCATION>"
$ export DASK_CLOUDPROVIDER__AZURE__AZUREVM__RESOURCE_GROUP="<RESOURCE GROUP>"
$ export DASK_CLOUDPROVIDER__AZURE__AZUREVM__VNET="<VNET>"
$ export DASK_CLOUDPROVIDER__AZURE__AZUREVM__SECURITY_GROUP="<SECUROTY GROUP>"

0 comments on commit 4d2d9ea

Please sign in to comment.