Skip to content

Unregister listeners on Output.close - #1993

Merged
pekkaklarck merged 1 commit into
robotframework:masterfrom
WojtekKowaluk:unregister-listeners
Jun 2, 2015
Merged

pekkaklarck merged 1 commit into
robotframework:masterfrom
WojtekKowaluk:unregister-listeners

Conversation

@WojtekKowaluk

Copy link
Copy Markdown
Contributor

Fix for #1992

@robotci

robotci commented May 13, 2015

Copy link
Copy Markdown

Admin, can CI be enabled?

Comment thread utest/running/test_running.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.

Do I get it right that the verified "[from listener 1]" was already created by the first run and here it is tested that the second run didn't produce new output? I think it would be better to add a method like RunningTestCase._clear_outputs that could be called before the second run and then verified that outputs are empty after the second run. Same could then me done also with test_listeners in test_run_and_rebot.py.

@pekkaklarck

Copy link
Copy Markdown
Member

I looked at the PR and the related code and have two general comments:

  • The related code is horrible.
  • The PR looks good.

Looking at the code, it seems Logger.close() that is used when using robot.run closes all registered loggers by calling close() of each logger. If I got it right, the Logger.unregister_logger call you added doesn't close loggers. If that's the case, listeners' close won't be called and also possible debug file will be left open.

Could you verify my analysis by adding close to the listener you used in tests and verifying is it called or not? If it's not called, we need to figure out a good place to close unregistered loggers. It would be convenient if LoggerCollection.unregister_logger would do that automatically, but I'm not sure do loggers it gets always have close.

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

Yes, you are right. After my change close of listener is not called anymore. I will look into it. I will also improve unit tests.

@pekkaklarck

Copy link
Copy Markdown
Member

Did I get it right that abbf1eb didn't yet fix problems with close?

@robotci: Whitelist

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

Yes, I'm still thinking how to do that right. Maybe you have some idea?

Comment thread src/robot/output/output.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.

Is there a reason to have _registered_logger as a class attribute? Is there a need to share a list of loggers? If not, this definitely should be an instance attribute.

@pekkaklarck

Copy link
Copy Markdown
Member

There seems to be two easy solutions how to close loggers:

  1. Output.close can all close for all its _registered_loggers. This is pretty much what Output.close does before resetting all loggers.
  2. LoggerCollection.unregister_logger that actually unregisters loggers calls close for the logger it gets. This has a problem that all loggers don't necessarily have close. There could also be cases where the caller wants to call close separately.

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

Thank you. I have decided to use first way. Seems to be best way for now. I also did other changes you have requested.

I have one extra question:
In test listener I had to use sys.__stdout__ for printing because it seems nothings else works with RunningTestCase. Is this OK? Is there better way?

@pekkaklarck

Copy link
Copy Markdown
Member

Using sys.__stdout__ ought to be fine. I guess Robot has sys.stdout intercepted at that point. Would be a lot easier to test this if APIs allowed passing listeners as objects. :)

Comment thread src/robot/output/output.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.

It would perhaps be a little more clear to format the above like this:

for logger in self._registered_loggers:
    logger.close()
    LOGGER.unregister_logger(logger)

@pekkaklarck

Copy link
Copy Markdown
Member

This PR looks very good. For consistency reasons new RunningTestCase.close_output should be renamed to _close_outputs. Other two line notes are probably matter of taste and not really that important.

After you are done, please squash the commits and I'll merge this. If you can do it during Tuesday, we'll still get it to 2.9a2.

@jussimalinen

Copy link
Copy Markdown
Member

@WojtekKowaluk, do you think you get this PR finalised today? We try to create 2.9a2 on Wednesday and are now descoping issues we cannot get into it. This is pretty much ready and we'd like to get it closed.

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

I am working on it right now. I will do my best to finish it today.

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

@pekkaklarck Are you sure you want this method to be named _close_outputs and not _clear_outputs. It makes more sense for me.

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

@pekkaklarck @jussimalinen commits are squashed now, let me know if anything else should be done.

Comment thread utest/api/test_run_and_rebot.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.

Is run needed here instead of run_without_outputs that's used by above tests?

@pekkaklarck

Copy link
Copy Markdown
Member

Yeah, definitely _clear_outputs and not _close_outputs.

In the final review I noticed that calling listeners' close method doesn't seem to be tested. Can you still take a look at that and the other two line notes? Sorry about not noticing these earlier.

@WojtekKowaluk

Copy link
Copy Markdown
Contributor Author

Fixed.

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 also reset self._registered_loggers. I can add that.

pekkaklarck added a commit that referenced this pull request Jun 2, 2015
Unregister listeners in `Output.close`. This makes sure listeners are unregistered when using `TestSuite.run` API.
@pekkaklarck
pekkaklarck merged commit 0886b61 into robotframework:master Jun 2, 2015
pekkaklarck added a commit that referenced this pull request Jun 2, 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.

4 participants