File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -436,7 +436,7 @@ function pyimport(name::AbstractString)
436
436
if ispynull (o)
437
437
if pyerr_occurred ()
438
438
e = PyError (" PyImport_ImportModule" )
439
- if e . T . o == @pyglobalobjptr (:PyExc_ImportError )
439
+ if pyisinstance (e . val, @pyglobalobjptr (:PyExc_ImportError ) )
440
440
# Expand message to help with common user confusions.
441
441
msg = """
442
442
The Python package $name could not be found by pyimport. Usually this means
Original file line number Diff line number Diff line change @@ -321,6 +321,18 @@ const PyInt = pyversion < v"3" ? Int : Clonglong
321
321
@test ! ispynull (PyObject (3 ))
322
322
@test ispynull (pydecref (PyObject (3 )))
323
323
324
+ ex = try
325
+ pyimport (" s p a m" )
326
+ catch ex
327
+ ex
328
+ end
329
+ @test ex isa PyCall. PyError
330
+ @test occursin (" could not be found by pyimport" , ex. msg)
331
+ # Make sure we are testing ModuleNotFoundError here:
332
+ if PyCall. pyversion >= v " 3.6"
333
+ @test pyisinstance (ex. val, pybuiltin (" ModuleNotFoundError" ))
334
+ end
335
+
324
336
@test ! ispynull (pyimport_conda (" inspect" , " not a conda package" ))
325
337
import Conda
326
338
if PyCall. conda
You can’t perform that action at this time.
0 commit comments