<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi folks</div><div><br></div><div>I've been looking at a potential large change to the GDAL test suite, replacing some of the worst parts. I thought I'd bring it up for discussion here, in case anyone has any wisdom or strong feelings about it.</div><div><br></div><div>I've made a ticket at <a href="https://github.com/OSGeo/gdal/issues/949">https://github.com/OSGeo/gdal/issues/949</a> . <br></div><div><br></div><div>Essentially my plan is to use <a href="https://docs.pytest.org/en/latest/">pytest</a> as both a test runner and a helper library. We would remove or replace large parts of the `gdaltest` utilities with pytest equivalents.</div><div><br></div><div>To give an idea of the main changes, this code:</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-family:monospace,monospace">if ds.GetLayer(0).GetSpatialRef() is not None:<br> gdaltest.post_reason('did not get expected spatial ref')<br> return 'fail'</span><br></blockquote></div><div>would change to:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><span style="font-family:monospace,monospace">assert ds.GetLayer(0).GetSpatialRef() is None, 'did not get expected spatial ref'</span></div></blockquote><div><br></div><div>The pytest runner gives contextual tracebacks from assert statements, as well as relevant variables and line numbers.</div><div><br></div><div>Other changes:</div><div> * The `gdaltest_list` and the `__main__` entry point at the bottom of each file will be removed. Some tests will be renamed if they don't already start with `test_`.</div><div> * The `<name>_cleanup` fixture will be turned into a <a href="https://docs.pytest.org/en/latest/fixture.html#scope-sharing-a-fixture-instance-across-tests-in-a-class-module-or-session">module-scoped fixture</a>. This allows users to run any number of tests in the module, and the cleanup fixture will be invoked once after all of them are finished. If I find corresponding setup functions I will make them into fixtures too, but I haven't seen those so far in my digging.<br></div><div><div><br></div><div>Other,
more intrusive changes are possible but this is what I'm considering targeting as a
first step. It is fairly straightforward to automate this change; I have a script in progress already to do that.<br></div><div><br></div><div>I intend to make a compatibility shim for the old-style tests that can't easily be automatically updated. The shim would be a decorator, perhaps called `@old_test`, which would take 'skip' or 'fail' return values from tests and turn them into the appropriate `assert False` or `pytest.skip()` calls.<br></div></div><div><br></div><div>I don't intend to make any changes to the C++ tests.</div><div><br></div><div>A couple of complicating factors to be aware of:</div><div><ul><li>pytest only supports python 2.7+. The tests already only run in 2.7+ in Travis, so no big deal there. I think it's perfectly reasonable to only support 2.7+ these days, given that 2.6 has been unsupported since 2013, but I thought I'd mention it.</li><li>pytest has no builtin way of <i>ordering</i> tests. It is assumed that tests are independent of each other. In practice, all tests are run in alphabetical name order within a given module. It appears to me that some of GDAL's tests are <i>not</i> independent of each other within the same module. However, most are already in alphabetical name order, so I don't believe this is a problem; we are not worse off with pytest than previously.<br></li></ul></div></div><div dir="ltr"><br></div><div>Please let me know your thoughts.<br></div><div dir="ltr"><div><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Regards,</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Craig de Stigter<br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Developer</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Koordinates</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><a href="tel:+64%2021%20256%209488" style="color:rgb(17,85,204)" target="_blank">+64 21 256 9488</a> / <a href="http://koordinates.com/" style="color:rgb(17,85,204)" target="_blank">koordinates.com</a> / <a href="https://twitter.com/koordinates" style="color:rgb(17,85,204)" target="_blank">@koordinates</a></div></div></div></div></div></div></div></div></div>