Skip to content

Commit

Permalink
logging: close log_file_handler
Browse files Browse the repository at this point in the history
Maybe fixes/helps with:

https://pytest-dev.visualstudio.com/pytest/_build/results?buildId=549&view=logs&jobId=b93ccf05-0a7e-58c4-578e-33859c8603c3&taskId=d709c56b-0a9a-5e23-1f1b-6f5848010da1&lineStart=63&lineEnd=64&colStart=1&colEnd=1

  > Exception ignored in: <_io.FileIO name='…\\\\pytest-0\\\\popen-gw1\\\\test_root_logger_affected0\\\\pytest.log' mode='wb' closefd=True>
  > ResourceWarning: unclosed file <_io.TextIOWrapper name='…\\\\pytest-0\\\\popen-gw1\\\\test_root_logger_affected0\\\\pytest.log' mode='w' encoding='UTF-8'>

Analysis:

`test_collect_functools_partial` fails (on purpose via `sys.exit`),
because during its collection this shows up on its stderr (via
`pytest_make_collect_report`).

BUT, the exception and ResourceWarning are referring to the file "pytest.log"
from another test (`test_root_logger_affected`, based on the path).

In another job the same file from this test is involved, but fails
another test then (TestRequestBasic.test_request_addfinalizer).
https://pytest-dev.visualstudio.com/pytest/_build/results?buildId=549&view=logs&jobId=eb23edc9-fa61-53da-8734-34b65fb77a8c&taskId=29ab628b-f8ff-5db3-44d6-286eec35d862&lineStart=65&lineEnd=66&colStart=1&colEnd=1

So another test is getting the ResourceWarning in its stderr while
collecting modules.

This appears to be related to xdist/parallelism.

On Travis TestRequestBasic.test_request_attributes_method caught it [1],
also via/for "gw0/test_root_logger_affected0/pytest.log".

1: https://travis-ci.org/pytest-dev/pytest/jobs/510010086#L785
  • Loading branch information
blueyed committed Mar 23, 2019
1 parent 503fe39 commit 92ffe42
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/_pytest/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ def pytest_sessionfinish(self):
if self.log_file_handler is not None:
with catching_logs(self.log_file_handler, level=self.log_file_level):
yield
self.log_file_handler.close()
else:
yield

Expand Down

0 comments on commit 92ffe42

Please sign in to comment.