Skip to content

Allow to pass listener instances to robot.run - #1987

Merged
pekkaklarck merged 1 commit into
robotframework:masterfrom
WojtekKowaluk:pass-listener-instances
Jun 10, 2015
Merged

pekkaklarck merged 1 commit into
robotframework:masterfrom
WojtekKowaluk:pass-listener-instances

Conversation

@WojtekKowaluk

Copy link
Copy Markdown
Contributor

implements #1969

@robotci

robotci commented May 8, 2015

Copy link
Copy Markdown

Admin, can CI be enabled?

Comment thread src/robot/output/listeners.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should check against basetring to allow passing listener name as str and unicode.

@pekkaklarck

Copy link
Copy Markdown
Member

This looks very good! I especially like that you have added some unit tests for this functionality. There are, however, few issues still to be sorted out. I already added some line notes, but there are few additional things to do or at least consider:

  • This functionality must be documented. Most logical place to document this is in the docstring of robot.run method.
  • Should consider testing this also with running.TestSuite.run method. Testing this on higher level with robot.run is probably adequate as I can't see how this could be broken in TestSuite.run, but we have added many somewhat duplicate tests to utest/runing/test_running.py to make it certain both APIs work.
  • Should also consider documenting this on TestSuite.run level. There it might actually be better to just add a note that options have same semantics as options passed to robot.run. That would avoid duplicate documentation as well as forgetting to document something similar in both places in the future.

@pekkaklarck

Copy link
Copy Markdown
Member

@robotci: Whitelist

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

hello, I have improved code according to your comments. I have added test for TestSuite.run and seems there is a problem. When listeners are registered in one TestSuite.run call, they are still active in following calls. I am trying to figure out what is root cause of this behaviour.

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

I just checked this with master branch (with .py file module listeners) and behaviour is the same. Seems listener are not unregistered correctly after TestSuite.run call. I will investigate it more unless you have some idea.

@pekkaklarck

Copy link
Copy Markdown
Member

Interesting. Sounds like a bug to me. We've had similar problems with preserved state when using programmatic APIs also earlier. If you have confirmed this, please submit a separate issue about it. If you have found a fix, please also submit a separate PR.

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

I have added bit of documentation. Also created issue about listeners not being unregistered between TestSuite.run calls: #1992

Comment thread src/robot/conf/settings.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that you only wanted to support listeners, but I nevertheless think it would be OK to just modify _split_args_from_name_or_path to have this at the beginning:

if not isinstance(value, basestring):
    return value, []

If someone passes non-string value to other settings, things will break anyway. A big benefit would be that I could add support for instances to model modifiers separately.

@pekkaklarck

Copy link
Copy Markdown
Member

This looks great! Please take a look at the line notes and comment if you disagree with them.

One thing I don't like so much anymore in the overall design is that in settings listeners etc. would be a tuple (name, args) or (instance, []). I'm starting to think it would be better to just keep listener etc. there as it is given, and handle values where they are actually needed. To avoid duplication, we could move the logic currently in _split_args_from_name_or_path to a general utility function. After that __init__ of ListenerProxy could be changed to something like this:

def __init__(self, listener):
    if isinstance(listener, basestring):
        name, args = utils.split_args_from_name_or_path(listener)
        listener = self._import_listener(name, args)
    else:
        name = utils.type_name(listener)
    # ...

I think this would be better design than what we decided earlier. What do you think @WojtekKowaluk? If you agree, should we switch to that design immediately or first implement this using the original design and then refactor?

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

I also think this current solution is not very elegant. I will attempt to refactor it like you say.

@pekkaklarck

Copy link
Copy Markdown
Member

Great! A good first step would be just creating the split_args_from_name_or_path utility function. It probably should go to utils/text.py where we recently added split_tags_from_doc. Old unit test class TestSplitArgsFromNameOrPath should also be moved, with needed modifications, from test_settings.py to test_text.py.

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

I have refactored the code. I also went with your other suggestion except adding state to test listener (just skipped it for now, I'm not saying it's bad idea). What do you think?

Comment thread src/robot/conf/settings.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed if nothing special is done the value.

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

Fixed.

@pekkaklarck

Copy link
Copy Markdown
Member

Looks great! Please squash the commits and I'm happy to merge this. Do you want to continue w/ var files and modifiers or should I take care of them?

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

Commits are squashed. I can continue with var files and visitors in new PR if you don't mind waiting for it a bit.

pekkaklarck added a commit that referenced this pull request Jun 10, 2015
Allow to pass listener instances to robot.run. Part of #1969.
@pekkaklarck
pekkaklarck merged commit 7dd3a9b into robotframework:master Jun 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants