use prerun modifier to remove teardown/setup keyword

290 views
Skip to first unread message

Joseph Lorenzini

unread,
Jan 16, 2016, 1:59:59 PM1/16/16
to robotframework-users
all:

I am trying to use a prerun modifier to programmatically turn teardown/setup on or off for a test case. This is to aid in debugging when you only temporarily want to disable a teardown so you can see what state the system was in when the bug occurred.

I am assuming its my lack of familiar with the data model. However, when i try to do this in the prerun modfier class. I get an attribute error.

    test.keywords.teardown = None

Any pointers on how to remove the teardown keyword this way? Sample code below.

Thanks,
Joe


class TestTeardown(SuiteVisitor):
    """Visitor that keeps only every Xth test in the visited suite structure."""

    def visit_test(self, test):
        test.keywords.teardown = None

Joseph Lorenzini

unread,
Jan 16, 2016, 2:19:34 PM1/16/16
to robotframework-users
I think i figured it out. This seems to do the trick.


Joe 

Pekka Klärck

unread,
Jan 17, 2016, 4:28:45 PM1/17/16
to Joseph Lorenzini, robotframework-users
Hello,

The reason `test.teardown = None' doesn't work is that `setup` and
`teardown` are read-only propertys, but they could definitely be
settable. Could you submit an issue about it? Even better if you can
create a pull request.

It's great that setting `teardown.name = None` works, but it fails for
AttributeError if you don't have a teardown in the first place. In
general it would be cleaner to remove the teardown altogether. I
though this would work

if test.keywords.teardown:
test.keywords.pop()

but it seems ItemList object that Keywords object inherits doesn't
have `pop`. Instead this ought to work:

if test.keywords.teardown:
test.keywords[-1:] = []

It would be a good idea to add `pop` to ItemList to make it easier to
use. Could you submit an issue/pr about that too? `pop` could be used
by the aforementioned settable `setup/teardown`.

Cheers,
.peke
> --
> You received this message because you are subscribed to the Google Groups
> "robotframework-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to robotframework-u...@googlegroups.com.
> To post to this group, send email to robotframe...@googlegroups.com.
> Visit this group at https://groups.google.com/group/robotframework-users.
> For more options, visit https://groups.google.com/d/optout.



--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Joseph Lorenzini

unread,
Jan 18, 2016, 1:46:22 PM1/18/16
to Pekka Klärck, robotframework-users
Hi Pekka,

Here are the github issues you asked for.
Since it sounds like you think it would be cleanest to use pop for 2302, it seems like 2303 should be implemented first. I would be happy to submit a PR, but I think I'll need a little high level guidance on the implementation first. I assume we can discuss in the github issue.

Thanks,
Joe

Pekka Klärck

unread,
Jan 18, 2016, 2:12:10 PM1/18/16
to Joseph Lorenzini, robotframework-users

Great! Already commented #2303.

Sent from my mobile.

Reply all
Reply to author
Forward
0 new messages