Skip to content

CI: Check for file leaks in _all_ tests #35711

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 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8eb547e
CI: avoid file leaks in sas_xport tests
jbrockmendel Aug 12, 2020
bd953bf
CLN: reuse context inside decorator
jbrockmendel Aug 12, 2020
c114449
TST: check for leaked socket connections
jbrockmendel Aug 12, 2020
e2e5043
Merge branch 'master' of https://github.com/pandas-dev/pandas into ci…
jbrockmendel Aug 12, 2020
c2a362c
open file later
jbrockmendel Aug 12, 2020
37902db
Merge branch 'master' of https://github.com/pandas-dev/pandas into ci…
jbrockmendel Aug 13, 2020
e75a15b
Fix incorrect file closing in read_sas
jbrockmendel Aug 13, 2020
f337be4
TST: make check_file_leaks an auto-use fixture for all tests
jbrockmendel Aug 12, 2020
6119a92
Merge branch 'master' of https://github.com/pandas-dev/pandas into ci…
jbrockmendel Aug 13, 2020
811b9d0
Merge branch 'master' of https://github.com/pandas-dev/pandas into ci…
jbrockmendel Aug 14, 2020
430567b
BUG: unclosed file handle in mmap
jbrockmendel Aug 14, 2020
1c3bf73
TST: close connections opened by sqlalchemy
jbrockmendel Aug 14, 2020
7aa2976
Merge branch 'master' of https://github.com/pandas-dev/pandas into ci…
jbrockmendel Aug 17, 2020
415294c
Move fixture to tests.io.conftest
jbrockmendel Aug 17, 2020
c701b6f
Merge branch 'master' of https://github.com/pandas-dev/pandas into ci…
jbrockmendel Aug 17, 2020
a74fe3d
Merge branch 'master' of https://github.com/pandas-dev/pandas into ci…
jbrockmendel Aug 17, 2020
6afb943
Merge branch 'master' of https://github.com/pandas-dev/pandas into ci…
jbrockmendel Aug 18, 2020
13f7540
Avoid sqlite file leak in ipython test
jbrockmendel Aug 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ def add_imports(doctest_namespace):
doctest_namespace["pd"] = pd


@pytest.fixture(autouse=True)
def check_file_leaks():
"""
Check that a test does not leak file handles.
"""
with td.file_leak_context():
yield


# ----------------------------------------------------------------
# Common arguments
# ----------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ def get_handle(
try:
wrapped = _MMapWrapper(f)
f.close()
handles.remove(f)
handles.append(wrapped)
f = wrapped
except Exception:
# we catch any errors that may have occurred
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ def _get_all_tables(self):
return table_list

def _close_conn(self):
pass
# https://docs.sqlalchemy.org/en/13/core/connections.html#engine-disposal
self.conn.dispose()


class PandasSQLTest:
Expand Down Expand Up @@ -1242,7 +1243,7 @@ class _TestSQLAlchemy(SQLAlchemyMixIn, PandasSQLTest):
def setup_class(cls):
cls.setup_import()
cls.setup_driver()
conn = cls.connect()
conn = cls.conn = cls.connect()
conn.connect()

def load_test_data_and_sql(self):
Expand Down