basyx-python-sdk icon indicating copy to clipboard operation
basyx-python-sdk copied to clipboard

sdk: `test_tutorials.py` is effectively no-op

Open hpoeche opened this issue 2 months ago • 3 comments

We have a test file sdk/test/examples/test_tutorials.py, that checks the tutorials under sdk/basyx/aas/examples run without errors and produce correct results. Because the tutorials are written as plain script files that do not wrap the execution inside a if __name__ == "__main__" guard, the testing works by simply importing the tutorial file.

See test_tutorial_create_simple_aas() as example: https://github.com/eclipse-basyx/basyx-python-sdk/blob/29eda6f00f175e4488502a470acc93d1648e4e8d/sdk/test/examples/test_tutorials.py#L24-L30

The reformatting with ruff in #601 removed these imports as they seem unused to the linter. Therefore, most of the tests are currently no-ops. https://github.com/eclipse-basyx/basyx-python-sdk/blob/29eda6f00f175e4488502a470acc93d1648e4e8d/sdk/test/examples/test_tutorials.py#L34-L37

We should reintroduce the imports, guard them by # noqa: F401 and also re-check the changes from #601 for other unwanted removals.

hpoeche avatar Sep 18 '26 14:09 hpoeche

A probably more clean way to run the tutorial files content than using the from ... import ... statement, is using the builtin package importlib to import and thereby run the modules code. This also prevents ruff from detecting this import as unused.

hpoeche avatar Sep 20 '26 10:09 hpoeche

I don't know if I like the current "testing" at all. You are right that removing the imports killed the only options the assert statements had to fail somewhere, but "running" them by importing seems weird and risky.

I dont see the harm that wrapping the tutorials in a def main() would do. Then we can include them in the test through explicit main() calls and dont have to suppress ruff in any way.

JAB1305 avatar Sep 27 '26 19:09 JAB1305

I agree that it's a bit hacky, but we simply wanted to guard against obvious issues in the tutorials. What about reintroducing the import statements and simply adding an ignore statement for ruff with the explanation why?

s-heppner avatar Oct 07 '26 07:10 s-heppner