Skip to content

Support configuring virtual suite created when running multiple suites with __init__.robot #4015

Closed

Description

@far3ll

I'm fairly familiar with Testcase and Suite Setups/Teardowns and use them heavily in my projects.
But since I have multiple suites (which each represents a different hardware system with its own suite setup and teardown), each containing up to 60 testcases (also with setup and teardown), Robot Framework misses the option of a final "Run" teardown.

Some systems are not tested all the times, so these suites are deselected for specific runs (handled by RED GUI "Run Configurations").
Currently I implemented a "final" independent suite, which has some clean-up and logging/informing mechanisms implemented. Drawback of this implementation is, that this also counts as "passed testcase" and, the more problematic point: it will not get executed if a fatal error occurs.

Handling those clean-up mechanics is also not possible in one of those suite teardowns, since it is unclear, which suite will be executed last or even executed at all. And since all teardowns are somewhat generic and differ only in one or two parameters, it is unfeasible to have a special teardown for last suite.

My suggestion would be (if not already done, I could not find any implementation or documentation) to have an additional command line argument (--overall-teardown or --general-teardown) which points to a suite-file, where all the necessary final tear-down cases are written down.
Then, it also has to be clarified in what way this will interact with rebot or if it could even be included in rebot.

Is this a suitable suggestion for RF?

Additional Info:

  • Robotframework 3.2.2
  • RED - Robot Editor 0.9.5
  • Python 3.7.9 x64
  • Windows 10 x64

Activity

  1. pekkaklarck commented on Jun 19, 2021

    @pekkaklarck
    Member

    Typically you accomplish this by having a nested test suite directory with a top level directory having an __init__.robot file with whatever suite teardown you need. If I got it right, you are running tests like robot tests.robot more.robot and thus don't have such a natural place for a teardown. Notice that when running tests like this, Robot automatically creates a new "virtual" suite containing the executed suites as its child suites.

    I understand the need for a top level teardown when executing multiple suites, but having a separate command line option to specify the teardown has some problems:

    • If you just specify that you want to run My Keyword as a teardown, Robot doesn't know where it finds the keyword unless you tell it somehow. In __init__.robot files this isn't a problem because you can use normal library and resource imports. This could be handled, for exapmle, by requiring using long name like mylib.My Keyword and Robot then automatically importing mylib as library, but that's not too convenient.
    • We'd also need similar setting for specifying the top level setup.

    An easier and also more flexible solution would be making it possible to specify an __init__.robot file to use with the virtual top-level suite when running multiple suites. We could make it so that if one of the executed files is __init__.robot, then that's used to configure the virtual suite exactly like __init__.robot files typically configure suites created from directories. Basically the usage would be like robot __init__.robot tests.robot more.robot. A nice benefit of this approach is that it ought to be pretty easy to implement.

    Would this work for you @far3ll? Would someone be interested to look at implementing this? As I wrote, it shouldn't be too complicated but I won't have time for it in the near future myself. Would be happy to review PRs and help otherwise if needed.

  2. Snurppa commented on Jun 20, 2021

    @Snurppa

    I wandered here with similar problem. We basically run robot -X init.robot $tests teardown.robot, but with --exitonfailure and a failure in some test, we do not get the last teardown.robot run, because it's not part of the currently running suite that get expanded from script variable $tests. $tests is basically X amount of directories. All the dirs could have __init__.robot file, but would require adding afterwards hundreds of identical files to those sub directories.

    The init.robot and teardown.robot are basically used to open and close all browsers, as we run Selenium tests with RF.
    This has been done to minimize the time used required for the browser setup.

    All in all, I came here looking for such --general-teardown switch for the robot runner to hopefully solve our challenge. Pekka's suggestion about __init___.robot file to control the virtual suite would possibly solve this, if defining Suite Teardown there would cover all the tests given as argument to the robot runner and thus handle the teardown of "whole script execution scope" in case of failures when using --exitonfailure.

    Thanks anyway for all the efforts so far!

  3. pekkaklarck commented on Jun 20, 2021

    @pekkaklarck
    Member

    I quickly prototyped my proposal and liked the results and how easy the initial implementation was. I didn't/don't have time finish it now, but if someone would be interested to continue I'd be happy to help getting started. Biggest task is probably adding tests and updating documentation.

  4. far3ll commented on Jun 21, 2021

    @far3ll
    Author

    I was not aware of this __init__.robot approach with its nested suite setup and teardown capabilities. I did some tests and will think of how to implement this in our current test framework and if it fits our requirements so far.

    While doing some research and trying some different approaches, it got me thinking if our use-case for this teardowns (sending emails, saving/archiving artifacts, doing some clean-up) should be within the responsibility of Robot Framework. In the end, RF should handle testcases and the overall managing node (some CI tool, e.g. Jenkins) should be responsible for post-build processes (in that case a fatal error in any of those tests will not interrupt post-processing).

    Nonetheless, if working without CIs and doing some manual consistency tests in e.g. RED, the implementation mentioned by @pekkaklarck would be a very nice feature :) I am afraid, I am the wrong one to implement this, but maybe I will find some time in future.

    Also thank you very much for the efforts!

  5. pekkaklarck commented on Jun 21, 2021

    @pekkaklarck
    Member

    Yeah, executing a directory and having __init__.robot files on different levels makes it easy to have whatever granularity with setups and teardowns you need. I also agree sending emails etc. should typically be handled outside RF tests.

    Anyway, sometimes running individual files or directories is convenient and being able to configure the virtual suite created in these cases would be handy. Doing that with __init__.robot files would be convenient, consistent and also pretty easy to implement.

  6. changed the title [-]Missing Teardown after complete Run with multiple Suites finished[/-] [+]Support configuring virtual suite created when running multiple suites with `__init__.robot`[/+] on Sep 21, 2022
  7. added this to the v5.2 milestone on Sep 21, 2022
  8. self-assigned this
    on Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions