[gdal-dev] hardcoded paths in the testsuite

Even Rouault even.rouault at spatialys.com
Wed Apr 18 02:35:10 PDT 2018


Ben,

> 
> I noticed that the testsuite does things like this:
> 
> sys.path.append('../pymod')
> and:
> sys.path.append('../gcore')
> 
> Using hard-coded relative paths makes things fragile. It means you must
> be in the specific test directory for the tests to run -- it can't be
> run from anywhere. 

Actually there are a few scripts like autotest/ogr/ogr_sqlite.py that do

# Make sure we run from the directory of the script
if os.path.basename(sys.argv[0]) == os.path.basename(__file__):
    if os.path.dirname(sys.argv[0]) != '':
        os.chdir(os.path.dirname(sys.argv[0]))


Beyond the import of the other modules, all pathnames to test datasets also 
assume that the script is run from its directory.

> I think it would be better to rely on PYTHONPATH and
> control the module loading from outside the test code. What do you think?

Given the amount of changes that would be needed, I'm not convinced of the 
interest of this. And setting PYTHONPATH would be a bit annoying whereas it is 
not required for now.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list