Repository navigation
Conversation
…files (robotframework#5853) When discovering suite structure, SuiteStructureBuilder._is_init_file checked path.stem.lower() == '__init__'. For compound extensions like .robot.md and .robot.rst, path.stem retains .robot (e.g. __init__.robot), causing the initialization files to be treated as unrecognized hidden files and ignored. Compare path.name.lower() with f'__init__.{self.extensions.get_extension(path)}' instead, so compound extensions are properly recognized. Add unit tests and acceptance tests.
d-biehl
left a comment
There was a problem hiding this comment.
I reported #5853 and had planned to send a PR for it myself, so thanks a lot for picking this up! I tested the change locally on top of current master (Python 3.13). __init__.robot.md and __init__.robot.rst are now used as initialization files with the default extensions, with upper-case names, with --extension robot.md, with --parseinclude, when the init file is given directly as a data source, and with a custom parser for a compound extension. __init__.robot, and __init__.md with --extension md, work as before. The unit tests and the acceptance tests under parsing and cli/runner pass, and the new tests fail without the fix.
One behavior change worth knowing: if a directory contains both __init__.robot and __init__.robot.md, the second one now gets the usual "Ignoring second test suite init file" error instead of being silently ignored. I think that is correct.
| Check Log Message ${SUITE.setup.messages[0]} Init setup in .robot.md | ||
| Should Contain Tests ${SUITE} Example Test | ||
|
|
||
| Init file with '.robot.rst' extension |
There was a problem hiding this comment.
The other reST acceptance tests are tagged require-docutils (see Force Tags in atest/robot/parsing/data_formats/rest.robot), so they can be excluded when docutils is not installed:
| Init file with '.robot.rst' extension | |
| Init file with '.robot.rst' extension | |
| [Tags] require-docutils |
There was a problem hiding this comment.
Thanks for testing it so thoroughly, and for the pointer. Added [Tags] require-docutils to the .robot.rst test in aba2862, matching the other reST acceptance tests.
Summary
Fixes #5853.
When discovering test suite structure,
SuiteStructureBuilder._is_init_filepreviously checkedpath.stem.lower() == '__init__'.Because Python
pathlib.Path.stemonly strips the final suffix,Path('__init__.robot.md').stemevaluates to'__init__.robot'. As a result, valid suite initialization files with compound extensions (such as.robot.mdand.robot.rst) were not recognized as initialization files. Since their filename starts with_, they were subsequently treated as ignored files and skipped entirely.Changes
src/robot/parsing/suitestructure.py:_is_init_fileto verifypath.name.lower() == f"__init__.{self.extensions.get_extension(path)}".utest/parsing/test_suitestructure.py:TestSuiteStructureBuildertesting__init__.robot,__init__.robot.md,__init__.robot.rst, case insensitivity, and custom extensions.atest/robot/parsing/init_file_formats.robotandatest/testdata/parsing/init_file_formats/:__init__.robot.mdand__init__.robot.rstload suite documentation and execute suite setup properly.