Skip to content

Add support for logging in collection-phase#3986

Merged
twmr merged 4 commits into
pytest-dev:featuresfrom
twmr:fb3964
Sep 19, 2018
Merged

Add support for logging in collection-phase#3986
twmr merged 4 commits into
pytest-dev:featuresfrom
twmr:fb3964

Conversation

@twmr

@twmr twmr commented Sep 14, 2018

Copy link
Copy Markdown
Contributor

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

coveralls commented Sep 15, 2018

Copy link
Copy Markdown

Coverage Status

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

Comment thread src/_pytest/logging.py Outdated
"--log-cli-level"
) is not None or self._config.getini("log_cli")

@pytest.hookimpl(hookwrapper=True)

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.

Try first could possibly make it more robust

Copy link
Copy Markdown
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
Copy Markdown
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 ^^

Comment thread src/_pytest/logging.py Outdated
# so we can access the terminal reporter plugin.
self._setup_cli_logging()

# TODO write to file support needed?

@nicoddemus nicoddemus Sep 15, 2018

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.

@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
Copy Markdown
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
Copy Markdown
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

codecov Bot commented Sep 18, 2018

Copy link
Copy Markdown

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

codecov Bot commented Sep 18, 2018

Copy link
Copy Markdown

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.

Comment thread src/_pytest/logging.py Outdated

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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/_pytest/logging.py
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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