GeospatialPython / pyshp

This library reads and writes ESRI Shapefiles in pure Python.
MIT License
1.09k stars 259 forks source link

add/modify test routine for running pytest / ship test file with installation #243

Closed megies closed 2 years ago

megies commented 2 years ago

Describe the feature request

Might be worth a thought to also ship the test_shapefile.py file with the installation, so that tests can be run in installed versions (or in packaging, like done in conda-forge, see https://github.com/conda-forge/pyshp-feedstock).

Also, I noted that running pytest with doctests (pytest --doctest-modules shapefile.py) shows some failures while running python -c 'import shapefile; shapefile.test() (which seems like it runs doctest) does not.

Willing to contribute?

karimbahgat commented 2 years ago

For the first part, i've never encountered this use case, and a little afraid it will break something. Do you know how this would be done, is it just adding "test_shapefile" to the "py_modules" setup arg? Will this then make test_shapefile as an importable module on its own, eg import test_shapefile?

For the second part, i'm not sure what the reason is and not really able to explore, i suspect it might have something to do with the doctest customization that happens in shapefile.py. Let me know if you find out.

megies commented 2 years ago

For the first part, i've never encountered this use case, and a little afraid it will break something. Do you know how this would be done, is it just adding "test_shapefile" to the "py_modules" setup arg?

Yes, not sure how the setup is done here, since this is a single-file-only installation basically, I think. In general all the test files are submodules like any other.

Will this then make test_shapefile as an importable module on its own, eg import test_shapefile?

Yes, although as soon as there are multiple files in a project, everything will be submodules, so it would be more like import shapefile.test_shapefile

For the second part, i'm not sure what the reason is and not really able to explore, i suspect it might have something to do with the doctest customization that happens in shapefile.py. Let me know if you find out.

I did not look into it more.

I guess this is kind of a low-priority issue, and I'll close this ticket to not clutter the issue tracker. But it might be something to keep in the back of the head.