Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for logging in collection-phase #3986

Merged
merged 4 commits into from
Sep 19, 2018
Merged

Conversation

twmr
Copy link
Contributor

@twmr twmr commented Sep 14, 2018

The logging plugin does not output log messages generated during the
collection-phase when live-logging is enabled. This fixes this.

Fixes #3964

@twmr twmr changed the base branch from master to features September 14, 2018 23:54
@twmr twmr requested a review from nicoddemus September 15, 2018 00:32
@coveralls
Copy link

coveralls commented Sep 15, 2018

Coverage Status

Coverage increased (+0.03%) to 93.923% when pulling 18cc74b on thisch:fb3964 into a79dc12 on pytest-dev:features.

@@ -425,6 +424,21 @@ def _log_cli_enabled(self):
"--log-cli-level"
) is not None or self._config.getini("log_cli")

@pytest.hookimpl(hookwrapper=True)
Copy link
Member

Choose a reason for hiding this comment

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

Try first could possibly make it more robust

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thx for the suggestion. Probably it makes sense to use tryfirst also for the other hookimpls in the logging plugin, right?

Copy link
Member

Choose a reason for hiding this comment

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

@Thisch quite possible - i never did a formal review of hook orders proceed with caution ^^

# so we can access the terminal reporter plugin.
self._setup_cli_logging()

# TODO write to file support needed?
Copy link
Member

@nicoddemus nicoddemus Sep 15, 2018

Choose a reason for hiding this comment

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

@Thisch any reason not to? If there isn't a good reason, I would prefer this to go out feature-complete rather than need another iteration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because adding support for log-to-file support is trickier. Simply copying the ctx manager that are used in pytest_runtestloop does not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a working implementation now. It was necessary to remove the closing context manager.

The logging plugin does not output log messages generated during the
collection-phase when live-logging is enabled. This fixes this.

Fixes pytest-dev#3964
@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #3986 into features will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##           features    #3986      +/-   ##
============================================
+ Coverage      94.5%   94.54%   +0.04%     
============================================
  Files           107      107              
  Lines         23710    23721      +11     
  Branches       2353     2357       +4     
============================================
+ Hits          22406    22427      +21     
+ Misses          993      987       -6     
+ Partials        311      307       -4
Flag Coverage Δ
#doctesting 28.53% <46.66%> (+0.07%) ⬆️
#linux 94.41% <100%> (+0.04%) ⬆️
#nobyte 0% <ø> (ø) ⬆️
#numpy 28.15% <46.66%> (+0.02%) ⬆️
#pexpect 0% <ø> (ø) ⬆️
#pluggymaster 93.56% <100%> (-0.06%) ⬇️
#py27 92.66% <100%> (+0.04%) ⬆️
#py34 92.2% <100%> (+0.03%) ⬆️
#py35 92.21% <100%> (+0.03%) ⬆️
#py36 92.78% <100%> (+0.04%) ⬆️
#py37 92.42% <100%> (+0.03%) ⬆️
#trial 31.04% <46.66%> (-0.16%) ⬇️
#windows 93.29% <100%> (-0.55%) ⬇️
#xdist 18.43% <46.66%> (-0.04%) ⬇️
Impacted Files Coverage Δ
testing/logging/test_reporting.py 100% <100%> (ø) ⬆️
src/_pytest/logging.py 95.76% <100%> (+0.11%) ⬆️
src/_pytest/terminal.py 91.6% <0%> (+1.74%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a79dc12...d1a3aa7. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #3986 into features will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##           features    #3986      +/-   ##
============================================
+ Coverage      94.5%   94.54%   +0.04%     
============================================
  Files           107      107              
  Lines         23710    23734      +24     
  Branches       2353     2357       +4     
============================================
+ Hits          22406    22440      +34     
+ Misses          993      987       -6     
+ Partials        311      307       -4
Flag Coverage Δ
#doctesting 28.53% <46.66%> (+0.07%) ⬆️
#linux 94.42% <100%> (+0.04%) ⬆️
#nobyte 0% <ø> (ø) ⬆️
#numpy 28.2% <46.66%> (+0.07%) ⬆️
#pexpect 0% <ø> (ø) ⬆️
#pluggymaster 93.65% <100%> (+0.04%) ⬆️
#py27 92.66% <100%> (+0.04%) ⬆️
#py34 92.2% <100%> (+0.04%) ⬆️
#py35 92.22% <100%> (+0.04%) ⬆️
#py36 92.79% <100%> (+0.04%) ⬆️
#py37 92.42% <100%> (+0.04%) ⬆️
#trial 31.26% <46.66%> (+0.07%) ⬆️
#windows 93.84% <100%> (ø) ⬆️
#xdist 18.49% <46.66%> (+0.02%) ⬆️
Impacted Files Coverage Δ
testing/logging/test_reporting.py 100% <100%> (ø) ⬆️
src/_pytest/logging.py 95.76% <100%> (+0.11%) ⬆️
src/_pytest/terminal.py 91.6% <0%> (+1.74%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a79dc12...18cc74b. Read the comment docs.


if self.log_file_handler is not None:
with catching_logs(self.log_file_handler, level=self.log_file_level):
yield # run all the tests
Copy link
Member

Choose a reason for hiding this comment

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

this should be # perform collection 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll simply remove this comment.

self.log_file_handler, level=self.log_file_level
):
yield # run all the tests
with catching_logs(self.log_file_handler, level=self.log_file_level):
Copy link
Member

Choose a reason for hiding this comment

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

So in the end is not really necessary to close log_file_handler explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it is not necessary. An alternative to removing the closing ctx manager would be to create the log_file_handler object twice.

@nicoddemus
Copy link
Member

Great, thanks a lot for the work @Thisch!

As far as I'm concerned this can be merged when CI passes. 👍

@twmr twmr merged commit 83802d1 into pytest-dev:features Sep 19, 2018
@twmr twmr deleted the fb3964 branch September 19, 2018 18:47
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