Skip to content

Not clear how to run tests #108

Description

@mjstahlberg

Running just nosetests after python setup.py build fails:

% nosetests
EE
======================================================================
ERROR: Failure: ImportError (cannot import name '_swiglpk' from 'swiglpk' (/home/viech/src/swiglpk/swiglpk/__init__.py))
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/usr/lib/python3.12/site-packages/nose/loader.py", line 416, in loadTestsFromName
    module = self.importer.importFromPath(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/nose/importer.py", line 162, in importFromPath
    return self.importFromDir(dir_path, fqname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/nose/importer.py", line 209, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/nose/importer.py", line 117, in load_module
    return load_package(name, filename)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/nose/importer.py", line 71, in load_package
    spec.loader.exec_module(sys.modules[name])
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/viech/src/swiglpk/swiglpk/__init__.py", line 1, in <module>
    from .swiglpk import *
  File "/home/viech/src/swiglpk/swiglpk/swiglpk.py", line 10, in <module>
    from . import _swiglpk
ImportError: cannot import name '_swiglpk' from 'swiglpk' (/home/viech/src/swiglpk/swiglpk/__init__.py)

======================================================================
ERROR: test_swiglpk (test_swiglpk.TestSwiglpk.test_swiglpk)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/viech/src/swiglpk/test_swiglpk.py", line 24, in test_swiglpk
    print(glp_version())
          ^^^^^^^^^^^
NameError: name 'glp_version' is not defined

----------------------------------------------------------------------
Ran 2 tests in 0.004s

FAILED (errors=2)

So does the following attempt using PYTHONPATH:

% echo $python_path
/home/viech/src/swiglpk/build/lib.linux-x86_64-cpython-312

% ls $python_path/swiglpk
glpk.i  swiglpk.py  _swiglpk.cpython-312-x86_64-linux-gnu.so  __init__.py

% PYTHONPATH=$python_path nosetests
[exact same error]

The same goes for python -m unittest:

% python -m unittest
EE
======================================================================
ERROR: swiglpk (unittest.loader._FailedTest.swiglpk)
----------------------------------------------------------------------
ImportError: Failed to import test module: swiglpk
Traceback (most recent call last):
  File "/usr/lib/python3.12/unittest/loader.py", line 429, in _find_test_path
    package = self._get_module_from_name(name)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/unittest/loader.py", line 339, in _get_module_from_name
    __import__(name)
  File "/home/viech/src/swiglpk/swiglpk/__init__.py", line 1, in <module>
    from .swiglpk import *
  File "/home/viech/src/swiglpk/swiglpk/swiglpk.py", line 10, in <module>
    from . import _swiglpk
ImportError: cannot import name '_swiglpk' from partially initialized module 'swiglpk' (most likely due to a circular import) (/home/viech/src/swiglpk/swiglpk/__init__.py)


======================================================================
ERROR: test_swiglpk (unittest.loader._FailedTest.test_swiglpk)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_swiglpk
Traceback (most recent call last):
  File "/usr/lib/python3.12/unittest/loader.py", line 396, in _find_test_path
    module = self._get_module_from_name(name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/unittest/loader.py", line 339, in _get_module_from_name
    __import__(name)
  File "/home/viech/src/swiglpk/test_swiglpk.py", line 17, in <module>
    from swiglpk import *
  File "/home/viech/src/swiglpk/swiglpk/__init__.py", line 1, in <module>
    from .swiglpk import *
  File "/home/viech/src/swiglpk/swiglpk/swiglpk.py", line 10, in <module>
    from . import _swiglpk
ImportError: cannot import name '_swiglpk' from partially initialized module 'swiglpk' (most likely due to a circular import) (/home/viech/src/swiglpk/swiglpk/__init__.py)


----------------------------------------------------------------------
Ran 2 tests in 0.000s

FAILED (errors=2)

Again with PYTHONPATH:

% PYTHONPATH=$python_path python -m unittest
[exact same error]

What is the intended way to run the tests?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions