Skip to content

Remove unneeded 2nd _setup_cli_logging call #4719

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

Closed
wants to merge 1 commit into from

Conversation

twmr
Copy link
Contributor

@twmr twmr commented Feb 4, 2019

During the review of #4204 it was not noticed that _setup_cli_logging
was already called in the collection phase (pytest_collection). After #4204 was merged
_setup_cli_logging is called in two hooks: pytest_collection and
pytest_sessionstart. However, it only makes sense to call _setup_cli_logging once
(in the first called hook of the logging plugin).

Thanks for submitting a PR, your contribution is really appreciated!

Here's a quick checklist that should be present in PRs (you can delete this text from the final description, this is
just a guideline):

  • Create a new changelog file in the changelog folder, with a name like <ISSUE NUMBER>.<TYPE>.rst. See changelog/README.rst for details.
  • Target the master branch for bug fixes, documentation updates and trivial changes.
  • Target the features branch for new features and removals/deprecations.
  • Include documentation when adding new features.
  • Include new tests or update existing tests when applicable.

Unless your change is trivial or a small documentation fix (e.g., a typo or reword of a small section) please:

  • Add yourself to AUTHORS in alphabetical order;

During the review of pytest-dev#4204 it was not noticed that _setup_cli_logging
was already called in the collection phase (pytest_collection). Now
_setup_cli_Logging is called in two hooks: pytest_collection and
pytest_sessionstart. It only makes sense to call _setup_cli_logging once
(in the first called hook of the logging plugin).
@@ -513,6 +509,8 @@ def pytest_sessionfinish(self):

@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_sessionstart(self):
# This has to be called before the first log message is logged,
Copy link
Member

Choose a reason for hiding this comment

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

im wondering - shouldn't we do this as early as pytest_configure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, maybe. We can call it once the terminalwrapper and capturemanager plugins are configured (see code of _setup_cli_logging).

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've just stumbled upon this code in LoggingPlugin.init (which is called in pytest_configure):

            # sanity check: terminal reporter should not have been loaded at this point
            assert self._config.pluginmanager.get_plugin("terminalreporter") is None

So I guess that both capturemanager and terminalreporter are not available in pytest_configure

Copy link
Member

Choose a reason for hiding this comment

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

@Thisch i believe a @hookimpl(trylast=True) can sort that

Copy link
Member

Choose a reason for hiding this comment

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

it may be more tricky :/ i didnt account for setuptools entrypoints

@codecov
Copy link

codecov bot commented Feb 4, 2019

Codecov Report

Merging #4719 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4719      +/-   ##
==========================================
- Coverage   95.68%   95.67%   -0.02%     
==========================================
  Files         113      113              
  Lines       24970    24969       -1     
  Branches     2479     2479              
==========================================
- Hits        23892    23888       -4     
  Misses        762      762              
- Partials      316      319       +3
Flag Coverage Δ
#docs 29.66% <ø> (+0.07%) ⬆️
#doctesting 29.66% <ø> (+0.07%) ⬆️
#linting 29.66% <ø> (+0.07%) ⬆️
#linux 95.5% <ø> (-0.01%) ⬇️
#nobyte 92.28% <ø> (-0.02%) ⬇️
#numpy 93.1% <ø> (-0.02%) ⬇️
#pexpect 42.08% <ø> (-0.01%) ⬇️
#py27 93.68% <ø> (-0.02%) ⬇️
#py34 91.76% <ø> (+0.06%) ⬆️
#py35 91.76% <ø> (+0.06%) ⬆️
#py36 91.78% <ø> (+0.06%) ⬆️
#py37 93.8% <ø> (+0.01%) ⬆️
#trial 93.1% <ø> (-0.02%) ⬇️
#windows 93.85% <ø> (-0.03%) ⬇️
#xdist 93.71% <ø> (-0.01%) ⬇️
Impacted Files Coverage Δ
src/_pytest/logging.py 96.04% <ø> (-0.02%) ⬇️
src/_pytest/cacheprovider.py 95.75% <0%> (-1.42%) ⬇️

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 a945734...e3b862a. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Feb 4, 2019

Codecov Report

Merging #4719 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4719      +/-   ##
==========================================
- Coverage   95.68%   95.67%   -0.02%     
==========================================
  Files         113      113              
  Lines       24970    24969       -1     
  Branches     2479     2479              
==========================================
- Hits        23892    23888       -4     
  Misses        762      762              
- Partials      316      319       +3
Flag Coverage Δ
#docs 29.66% <ø> (+0.07%) ⬆️
#doctesting 29.66% <ø> (+0.07%) ⬆️
#linting 29.66% <ø> (+0.07%) ⬆️
#linux 95.5% <ø> (-0.01%) ⬇️
#nobyte 92.28% <ø> (-0.02%) ⬇️
#numpy 93.1% <ø> (-0.02%) ⬇️
#pexpect 42.08% <ø> (-0.01%) ⬇️
#py27 93.68% <ø> (-0.02%) ⬇️
#py34 91.76% <ø> (+0.06%) ⬆️
#py35 91.76% <ø> (+0.06%) ⬆️
#py36 91.78% <ø> (+0.06%) ⬆️
#py37 93.8% <ø> (+0.01%) ⬆️
#trial 93.1% <ø> (-0.02%) ⬇️
#windows 93.85% <ø> (-0.03%) ⬇️
#xdist 93.71% <ø> (-0.01%) ⬇️
Impacted Files Coverage Δ
src/_pytest/logging.py 96.04% <ø> (-0.02%) ⬇️
src/_pytest/cacheprovider.py 95.75% <0%> (-1.42%) ⬇️

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 a945734...e3b862a. Read the comment docs.

twmr added a commit to twmr/pytest that referenced this pull request Feb 4, 2019
@blueyed
Copy link
Contributor

blueyed commented Feb 5, 2019

Closing in favor of #4720.

@blueyed blueyed closed this Feb 5, 2019
twmr added a commit to twmr/pytest that referenced this pull request Feb 5, 2019
twmr added a commit to twmr/pytest that referenced this pull request Feb 6, 2019
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