Skip to content

Commit

Permalink
Use pkgutil.iter_modules to get un-imported module for `test_pre_im…
Browse files Browse the repository at this point in the history
…port` (#1085)

Changed this because IIUC `pkg_resources.working_set` is listing the installed distributions and not necessarily the importable modules; this becomes an issue if the distribution and module names aren't the same (e.g. one would `conda install pillow` and then `import PIL`), which was causing some failures in CI that seem unrelated to the changes here.

_Originally posted by @charlesbluca in #981 (comment)

Authors:
  - Charles Blackmon-Luca (https://github.com/charlesbluca)

Approvers:
  - Peter Andreas Entschev (https://github.com/pentschev)

URL: #1085
  • Loading branch information
charlesbluca authored Jan 17, 2023
1 parent 2eee5eb commit 52dd850
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions dask_cuda/tests/test_dask_cuda_worker.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import absolute_import, division, print_function

import os
import pkgutil
import subprocess
import sys
from unittest.mock import patch

import pkg_resources
import pytest

from distributed import Client, wait
Expand Down Expand Up @@ -194,9 +194,9 @@ def test_pre_import(loop): # noqa: F811
module = None

# Pick a module that isn't currently loaded
for m in pkg_resources.working_set:
if m.key not in sys.modules.keys():
module = m.key
for m in pkgutil.iter_modules():
if m.ispkg and m.name not in sys.modules.keys():
module = m.name
break

if module is None:
Expand Down
8 changes: 4 additions & 4 deletions dask_cuda/tests/test_local_cuda_cluster.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import asyncio
import os
import pkgutil
import sys
from unittest.mock import patch

import pkg_resources
import pytest

from dask.distributed import Client
Expand Down Expand Up @@ -263,9 +263,9 @@ async def test_pre_import():
module = None

# Pick a module that isn't currently loaded
for m in pkg_resources.working_set:
if m.key not in sys.modules.keys():
module = m.key
for m in pkgutil.iter_modules():
if m.ispkg and m.name not in sys.modules.keys():
module = m.name
break

if module is None:
Expand Down

0 comments on commit 52dd850

Please sign in to comment.