equinor / xtgeo

XTGeo Python class library for subsurface Surfaces, Cubes, Wells, Grids, Points, etc
https://xtgeo.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
110 stars 56 forks source link

Remove `testpath`, `testpathobj`, and `testsetup()` from `XTGeoDialog` #1093

Closed mferrera closed 6 months ago

mferrera commented 9 months ago

Currently many test files have a number of global variables that point to different xtgeo-testdata files. These files get their root path from

https://github.com/equinor/xtgeo/blob/56d76c34c29f2892623c880c8bac42c4d82a6677/src/xtgeo/common/xtgeo_dialog.py#L251-L266

This logic is unnecessary to expose to users. Further, some logic to simplify the test path was set up but not fully integrated throughout the test code

https://github.com/equinor/xtgeo/blob/56d76c34c29f2892623c880c8bac42c4d82a6677/conftest.py#L75-L82

This fixture should be updated with the default path and the numerous global filepaths at the top of many test files should be updated. It should also be used to set the test path in the global pytest namespace (though this may not work directly -- untested):

def pytest_configure(testpath):
    pytest.xtg_testpath = testpath

It is common to see a pattern like this in test code:

from xtgeo.common import XTGeoDialog

xtg = XTGeoDialog()
if not xtg.testsetup():
    raise SystemExit

TPATH = xtg.testpathobj
TESTFILE1 = TPATH / "3dgrids/reek/reek_sim_poro.roff"

Then, as a start, the test path imported from XTGeoDialog can be swapped with pytest.xtg_testpath

TPATH = pytest.xtg_testpath
TESTFILE1 = TPATH / "3dgrids/reek/reek_sim_poro.roff"

(untested, may need adjusting)