linz / gazetteer

New Zealand Gazetteer of official place names
http://www.linz.govt.nz/regulatory/place-names/find-name/new-zealand-gazetteer-official-geographic-names/new-zealand-gazetteer-search-place-names#zoom=0&lat=-41.14127&lon=172.5&layers=BTTT
Other
2 stars 2 forks source link

CI - test module imports fail #146

Closed SPlanzer closed 4 years ago

SPlanzer commented 4 years ago

run_tests.py

    test_suite = unittest.TestLoader().discover(__location__, pattern="test_*.py")

failed with the below

======================================================================
ERROR: test_data_handler (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_data_handler
Traceback (most recent call last):
  File "/usr/lib/python3.6/unittest/loader.py", line 428, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name
    __import__(name)
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 744, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/NZGBplugin/tests/test_data_handler.py", line 1, in <module>
    from . import database
  File "/usr/lib/python3/dist-packages/qgis/utils.py", line 744, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
ImportError: attempted relative import with no known parent package

strangely when changing the patter to the file it is failing on (as below) - The import is successful and test pass

    test_suite = unittest.TestLoader().discover(__location__, pattern="test_new_feature.py.py")
SPlanzer commented 4 years ago

removed py3 relative imports

https://stackoverflow.com/questions/34986900/python-unittest-failing-to-resolve-import-statements