From 788725ea90ca53f5aabe1caefd34b294d6d3dc2d Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 26 Nov 2021 16:05:24 -0800 Subject: [PATCH 01/17] WIP/CI: Debug ResourceWarnings unclosed io.BufferedRandom --- azure-pipelines.yml | 57 ----------------------------- ci/deps/actions-38-db-min.yaml | 1 + ci/deps/actions-38-db.yaml | 1 + ci/deps/actions-38-locale.yaml | 1 + ci/deps/actions-38-locale_slow.yaml | 1 + ci/deps/actions-38-slow.yaml | 1 + ci/deps/actions-38.yaml | 1 + ci/deps/actions-39-numpydev.yaml | 1 + ci/deps/actions-39-slow.yaml | 1 + ci/deps/actions-39.yaml | 1 + pandas/_testing/_warnings.py | 24 ++++++++---- 11 files changed, 25 insertions(+), 65 deletions(-) delete mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 6c685d09ab55a..0000000000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,57 +0,0 @@ -# Adapted from https://github.com/numba/numba/blob/master/azure-pipelines.yml -trigger: - branches: - include: - - master - - 1.3.x - paths: - exclude: - - 'doc/*' - -pr: - autoCancel: true - branches: - include: - - master - - 1.3.x - -variables: - PYTEST_WORKERS: auto - PYTEST_TARGET: pandas - -jobs: -# Mac and Linux use the same template -- template: ci/azure/posix.yml - parameters: - name: macOS - vmImage: macOS-10.15 - -- template: ci/azure/windows.yml - parameters: - name: Windows - vmImage: windows-2019 - -- job: py38_32bit - pool: - vmImage: ubuntu-18.04 - - steps: - - script: | - docker pull quay.io/pypa/manylinux2014_i686 - docker run -v $(pwd):/pandas quay.io/pypa/manylinux2014_i686 \ - /bin/bash -xc "cd pandas && \ - /opt/python/cp38-cp38/bin/python -m venv ~/virtualenvs/pandas-dev && \ - . ~/virtualenvs/pandas-dev/bin/activate && \ - python -m pip install --no-deps -U pip wheel setuptools && \ - pip install cython numpy python-dateutil pytz pytest pytest-xdist hypothesis pytest-azurepipelines && \ - python setup.py build_ext -q -j2 && \ - python -m pip install --no-build-isolation -e . && \ - pytest -m 'not slow and not network and not clipboard' pandas --junitxml=test-data.xml" - displayName: 'Run 32-bit manylinux2014 Docker Build / Tests' - - - task: PublishTestResults@2 - condition: succeededOrFailed() - inputs: - testResultsFiles: '**/test-*.xml' - failTaskOnFailedTests: true - testRunTitle: 'Publish test results for Python 3.8-32 bit full Linux' diff --git a/ci/deps/actions-38-db-min.yaml b/ci/deps/actions-38-db-min.yaml index f875f2ef88949..de5d06a393030 100644 --- a/ci/deps/actions-38-db-min.yaml +++ b/ci/deps/actions-38-db-min.yaml @@ -10,6 +10,7 @@ dependencies: - pytest-cov - pytest-xdist>=1.31 - hypothesis>=5.5.3 + - psutil # required - numpy<1.20 # GH#39541 compat for pyarrow<3 diff --git a/ci/deps/actions-38-db.yaml b/ci/deps/actions-38-db.yaml index 7b73f43b7ba03..411006d51f8b8 100644 --- a/ci/deps/actions-38-db.yaml +++ b/ci/deps/actions-38-db.yaml @@ -10,6 +10,7 @@ dependencies: - pytest-xdist>=1.31 - hypothesis>=5.5.3 - pytest-cov>=2.10.1 # this is only needed in the coverage build, ref: GH 35737 + - psutil # pandas dependencies - aiobotocore<2.0.0 diff --git a/ci/deps/actions-38-locale.yaml b/ci/deps/actions-38-locale.yaml index b7043735d9457..498ba1168dc66 100644 --- a/ci/deps/actions-38-locale.yaml +++ b/ci/deps/actions-38-locale.yaml @@ -11,6 +11,7 @@ dependencies: - pytest-xdist>=1.31 - pytest-asyncio>=0.12.0 - hypothesis>=5.5.3 + - psutil # pandas dependencies - beautifulsoup4 diff --git a/ci/deps/actions-38-locale_slow.yaml b/ci/deps/actions-38-locale_slow.yaml index 0ff5dd6c3f7f0..2fcf6ac77da73 100644 --- a/ci/deps/actions-38-locale_slow.yaml +++ b/ci/deps/actions-38-locale_slow.yaml @@ -11,6 +11,7 @@ dependencies: - pytest-cov - pytest-xdist>=1.31 - hypothesis>=5.5.3 + - psutil # pandas dependencies - beautifulsoup4=4.8.2 diff --git a/ci/deps/actions-38-slow.yaml b/ci/deps/actions-38-slow.yaml index 903bd25655bd2..468fb65480dc2 100644 --- a/ci/deps/actions-38-slow.yaml +++ b/ci/deps/actions-38-slow.yaml @@ -10,6 +10,7 @@ dependencies: - pytest-cov - pytest-xdist>=1.31 - hypothesis>=5.5.3 + - psutil # pandas dependencies - beautifulsoup4 diff --git a/ci/deps/actions-38.yaml b/ci/deps/actions-38.yaml index 899913d6e8c70..e4805ae5cbb72 100644 --- a/ci/deps/actions-38.yaml +++ b/ci/deps/actions-38.yaml @@ -11,6 +11,7 @@ dependencies: - pytest-cov - pytest-xdist>=1.31 - hypothesis>=5.5.3 + - psutil # pandas dependencies - numpy diff --git a/ci/deps/actions-39-numpydev.yaml b/ci/deps/actions-39-numpydev.yaml index 4a6acf55e265f..0883f18270224 100644 --- a/ci/deps/actions-39-numpydev.yaml +++ b/ci/deps/actions-39-numpydev.yaml @@ -9,6 +9,7 @@ dependencies: - pytest-cov - pytest-xdist>=1.31 - hypothesis>=5.5.3 + - psutil # pandas dependencies - python-dateutil diff --git a/ci/deps/actions-39-slow.yaml b/ci/deps/actions-39-slow.yaml index 2d723354935d2..2e065c7c49bb4 100644 --- a/ci/deps/actions-39-slow.yaml +++ b/ci/deps/actions-39-slow.yaml @@ -11,6 +11,7 @@ dependencies: - pytest-cov - pytest-xdist>=1.31 - hypothesis>=5.5.3 + - psutil # pandas dependencies - beautifulsoup4 diff --git a/ci/deps/actions-39.yaml b/ci/deps/actions-39.yaml index 8751651ece115..75095b0579231 100644 --- a/ci/deps/actions-39.yaml +++ b/ci/deps/actions-39.yaml @@ -10,6 +10,7 @@ dependencies: - pytest-cov - pytest-xdist>=1.31 - hypothesis>=5.5.3 + - psutil # pandas dependencies - beautifulsoup4 diff --git a/pandas/_testing/_warnings.py b/pandas/_testing/_warnings.py index 5f01996d0390d..f922a26ba6f6e 100644 --- a/pandas/_testing/_warnings.py +++ b/pandas/_testing/_warnings.py @@ -9,6 +9,8 @@ ) import warnings +from pandas.util._test_decorators import safe_import + @contextmanager def assert_produces_warning( @@ -155,14 +157,20 @@ def _assert_caught_no_extra_warnings( # suppress these, xref GH#38630 continue - extra_warnings.append( - ( - actual_warning.category.__name__, - actual_warning.message, - actual_warning.filename, - actual_warning.lineno, - ) - ) + warning_data = [ + actual_warning.category.__name__, + actual_warning.message, + actual_warning.filename, + actual_warning.lineno, + ] + + if actual_warning.category == ResourceWarning: + psutil = safe_import("psutil") + proc = psutil.Process() + flist = proc.open_files() + warning_data.append(flist) + + extra_warnings.append(tuple(warning_data)) if extra_warnings: raise AssertionError(f"Caused unexpected warning(s): {repr(extra_warnings)}") From 3c0124a819886d0b615595a1e5099b00ea590dca Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 26 Nov 2021 16:06:56 -0800 Subject: [PATCH 02/17] Use if statement --- pandas/_testing/_warnings.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/_testing/_warnings.py b/pandas/_testing/_warnings.py index f922a26ba6f6e..70a3a3c4da43d 100644 --- a/pandas/_testing/_warnings.py +++ b/pandas/_testing/_warnings.py @@ -166,9 +166,10 @@ def _assert_caught_no_extra_warnings( if actual_warning.category == ResourceWarning: psutil = safe_import("psutil") - proc = psutil.Process() - flist = proc.open_files() - warning_data.append(flist) + if psutil: + proc = psutil.Process() + flist = proc.open_files() + warning_data.append(flist) extra_warnings.append(tuple(warning_data)) From 172af5a1ef724aa591de6baba110e8282d95fdd1 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 26 Nov 2021 18:02:01 -0800 Subject: [PATCH 03/17] Trigger CI From cb1796720aadb747ded30125a92fd593fab1d123 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 26 Nov 2021 19:29:46 -0800 Subject: [PATCH 04/17] Add back azure for ResourceWarning checking --- azure-pipelines.yml | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 azure-pipelines.yml diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000000000..6c685d09ab55a --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,57 @@ +# Adapted from https://github.com/numba/numba/blob/master/azure-pipelines.yml +trigger: + branches: + include: + - master + - 1.3.x + paths: + exclude: + - 'doc/*' + +pr: + autoCancel: true + branches: + include: + - master + - 1.3.x + +variables: + PYTEST_WORKERS: auto + PYTEST_TARGET: pandas + +jobs: +# Mac and Linux use the same template +- template: ci/azure/posix.yml + parameters: + name: macOS + vmImage: macOS-10.15 + +- template: ci/azure/windows.yml + parameters: + name: Windows + vmImage: windows-2019 + +- job: py38_32bit + pool: + vmImage: ubuntu-18.04 + + steps: + - script: | + docker pull quay.io/pypa/manylinux2014_i686 + docker run -v $(pwd):/pandas quay.io/pypa/manylinux2014_i686 \ + /bin/bash -xc "cd pandas && \ + /opt/python/cp38-cp38/bin/python -m venv ~/virtualenvs/pandas-dev && \ + . ~/virtualenvs/pandas-dev/bin/activate && \ + python -m pip install --no-deps -U pip wheel setuptools && \ + pip install cython numpy python-dateutil pytz pytest pytest-xdist hypothesis pytest-azurepipelines && \ + python setup.py build_ext -q -j2 && \ + python -m pip install --no-build-isolation -e . && \ + pytest -m 'not slow and not network and not clipboard' pandas --junitxml=test-data.xml" + displayName: 'Run 32-bit manylinux2014 Docker Build / Tests' + + - task: PublishTestResults@2 + condition: succeededOrFailed() + inputs: + testResultsFiles: '**/test-*.xml' + failTaskOnFailedTests: true + testRunTitle: 'Publish test results for Python 3.8-32 bit full Linux' From 0775d187ea58517d0c5ea63b83e8235cb5605ccf Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 26 Nov 2021 19:31:16 -0800 Subject: [PATCH 05/17] Also add psutil to azure deps --- ci/deps/azure-macos-38.yaml | 1 + ci/deps/azure-windows-38.yaml | 1 + ci/deps/azure-windows-39.yaml | 1 + 3 files changed, 3 insertions(+) diff --git a/ci/deps/azure-macos-38.yaml b/ci/deps/azure-macos-38.yaml index fe6fa6ca37e01..869016bdaf8ca 100644 --- a/ci/deps/azure-macos-38.yaml +++ b/ci/deps/azure-macos-38.yaml @@ -10,6 +10,7 @@ dependencies: - pytest-xdist>=1.31 - hypothesis>=5.5.3 - pytest-azurepipelines + - psutil # pandas dependencies - beautifulsoup4 diff --git a/ci/deps/azure-windows-38.yaml b/ci/deps/azure-windows-38.yaml index d4e2c482d1c1c..535144b8bc1b6 100644 --- a/ci/deps/azure-windows-38.yaml +++ b/ci/deps/azure-windows-38.yaml @@ -11,6 +11,7 @@ dependencies: - pytest-xdist>=1.31 - hypothesis>=5.5.3 - pytest-azurepipelines + - psutil # pandas dependencies - blosc diff --git a/ci/deps/azure-windows-39.yaml b/ci/deps/azure-windows-39.yaml index 0e352a80a6d34..1c4dfb0424dcb 100644 --- a/ci/deps/azure-windows-39.yaml +++ b/ci/deps/azure-windows-39.yaml @@ -11,6 +11,7 @@ dependencies: - pytest-xdist>=1.31 - hypothesis>=5.5.3 - pytest-azurepipelines + - psutil # pandas dependencies - beautifulsoup4 From 66f58d316cc928bc66ba359c4d48b960fa5d7290 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 26 Nov 2021 21:05:09 -0800 Subject: [PATCH 06/17] Trigger CI From 81f37d51a761169c8b90e3a2806beef234818f89 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 26 Nov 2021 23:26:20 -0800 Subject: [PATCH 07/17] Trigger CI From 696d21742201bb982dd0e2198585f4ad747e0a0d Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 27 Nov 2021 09:57:30 -0800 Subject: [PATCH 08/17] Just import directly --- pandas/_testing/_warnings.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pandas/_testing/_warnings.py b/pandas/_testing/_warnings.py index 70a3a3c4da43d..4289d15661d9a 100644 --- a/pandas/_testing/_warnings.py +++ b/pandas/_testing/_warnings.py @@ -9,8 +9,6 @@ ) import warnings -from pandas.util._test_decorators import safe_import - @contextmanager def assert_produces_warning( @@ -165,11 +163,11 @@ def _assert_caught_no_extra_warnings( ] if actual_warning.category == ResourceWarning: - psutil = safe_import("psutil") - if psutil: - proc = psutil.Process() - flist = proc.open_files() - warning_data.append(flist) + import psutil + + proc = psutil.Process() + flist = proc.open_files() + warning_data.append(flist) extra_warnings.append(tuple(warning_data)) From 07aedcdf995e37d48154331927fd5a60d29c2d3b Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 27 Nov 2021 20:59:31 -0800 Subject: [PATCH 09/17] Trigger CI From ce3348d41b9a5678fe77481141d200bd0039a718 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 27 Nov 2021 22:11:54 -0800 Subject: [PATCH 10/17] Trigger CI From 0652224b607a1fc055135e89d533a0800f065b13 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 27 Nov 2021 23:44:22 -0800 Subject: [PATCH 11/17] Trigger CI From d4542a070110b29184f2f135020350bace1168d2 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sun, 28 Nov 2021 10:05:53 -0800 Subject: [PATCH 12/17] Trigger CI From 3082ff4eaf0c17db6b72784c746d5daeb2af1da9 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sun, 28 Nov 2021 20:45:04 -0800 Subject: [PATCH 13/17] Check warnings everywhere --- pandas/conftest.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pandas/conftest.py b/pandas/conftest.py index 04589993b5f53..78960b9b509da 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -38,6 +38,7 @@ import hypothesis from hypothesis import strategies as st import numpy as np +import psutil import pytest from pytz import ( FixedOffset, @@ -199,6 +200,14 @@ def add_imports(doctest_namespace): doctest_namespace["pd"] = pd +@pytest.fixture(autouse=True) +def check_bufferedrandom_resourcewarning(): + proc = psutil.Process() + with tm.assert_produces_warning(None): + yield + print(proc.open_files(), flush=True) + + # ---------------------------------------------------------------- # Common arguments # ---------------------------------------------------------------- From 9455eb5f88d84e5bd5d17379544d47c4f36fdfb9 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sun, 28 Nov 2021 21:48:29 -0800 Subject: [PATCH 14/17] Only raise for ResourceWarning --- pandas/_testing/_warnings.py | 2 +- pandas/conftest.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pandas/_testing/_warnings.py b/pandas/_testing/_warnings.py index 43a1fa1dba509..ff0fa72ac772d 100644 --- a/pandas/_testing/_warnings.py +++ b/pandas/_testing/_warnings.py @@ -171,7 +171,7 @@ def _assert_caught_no_extra_warnings( extra_warnings.append(tuple(warning_data)) - if extra_warnings: + if extra_warnings and any(data[0] == ResourceWarning for data in extra_warnings): raise AssertionError(f"Caused unexpected warning(s): {repr(extra_warnings)}") diff --git a/pandas/conftest.py b/pandas/conftest.py index 78960b9b509da..a1e84cf067d6a 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -17,8 +17,6 @@ - Dtypes - Misc """ -# pyright: reportUntypedFunctionDecorator = false - from collections import abc from datetime import ( date, @@ -31,6 +29,9 @@ import operator import os +# pyright: reportUntypedFunctionDecorator = false +import sys + from dateutil.tz import ( tzlocal, tzutc, @@ -205,7 +206,9 @@ def check_bufferedrandom_resourcewarning(): proc = psutil.Process() with tm.assert_produces_warning(None): yield - print(proc.open_files(), flush=True) + # sys.stderr for xdist + # https://github.com/pytest-dev/pytest/issues/1693#issuecomment-233282644 + print(proc.open_files(), flush=True, file=sys.stderr) # ---------------------------------------------------------------- From 3dc24d45971b530f89105f0780ea27cff7bfd859 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 29 Nov 2021 11:16:19 -0800 Subject: [PATCH 15/17] -v in pytest, only print when there are files, install psutil in more places --- .github/workflows/python-dev.yml | 2 +- ci/deps/circle-38-arm64.yaml | 1 + ci/run_tests.sh | 2 +- pandas/conftest.py | 4 +++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-dev.yml b/.github/workflows/python-dev.yml index 824e7de3bde41..09567e8d59aa0 100644 --- a/.github/workflows/python-dev.yml +++ b/.github/workflows/python-dev.yml @@ -50,7 +50,7 @@ jobs: python -m pip install --upgrade pip setuptools wheel pip install -i https://pypi.anaconda.org/scipy-wheels-nightly/simple numpy pip install git+https://github.com/nedbat/coveragepy.git - pip install cython python-dateutil pytz hypothesis pytest>=6.2.5 pytest-xdist pytest-cov + pip install cython python-dateutil pytz hypothesis pytest>=6.2.5 pytest-xdist pytest-cov psutil pip list - name: Build Pandas diff --git a/ci/deps/circle-38-arm64.yaml b/ci/deps/circle-38-arm64.yaml index 6627ed5073b46..3f3863e250335 100644 --- a/ci/deps/circle-38-arm64.yaml +++ b/ci/deps/circle-38-arm64.yaml @@ -19,3 +19,4 @@ dependencies: - flask - pip: - moto + - psutil diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 9fea696b6ea81..6a728fdece6f8 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -19,7 +19,7 @@ if [[ $(uname) == "Linux" && -z $DISPLAY ]]; then XVFB="xvfb-run " fi -PYTEST_CMD="${XVFB}pytest -m \"$PATTERN\" -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE $PYTEST_TARGET" +PYTEST_CMD="${XVFB}pytest -v -m \"$PATTERN\" -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE $PYTEST_TARGET" if [[ $(uname) != "Linux" && $(uname) != "Darwin" ]]; then PYTEST_CMD="$PYTEST_CMD --ignore=pandas/tests/plotting/" diff --git a/pandas/conftest.py b/pandas/conftest.py index a1e84cf067d6a..8a88fe341ba66 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -208,7 +208,9 @@ def check_bufferedrandom_resourcewarning(): yield # sys.stderr for xdist # https://github.com/pytest-dev/pytest/issues/1693#issuecomment-233282644 - print(proc.open_files(), flush=True, file=sys.stderr) + open_files = proc.open_files() + if open_files: + print(open_files, flush=True, file=sys.stderr) # ---------------------------------------------------------------- From a8ff0906ff7d52aa1837c1114b311cf859b0f4cd Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 29 Nov 2021 13:01:15 -0800 Subject: [PATCH 16/17] -v too verbose --- ci/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 6a728fdece6f8..9fea696b6ea81 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -19,7 +19,7 @@ if [[ $(uname) == "Linux" && -z $DISPLAY ]]; then XVFB="xvfb-run " fi -PYTEST_CMD="${XVFB}pytest -v -m \"$PATTERN\" -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE $PYTEST_TARGET" +PYTEST_CMD="${XVFB}pytest -m \"$PATTERN\" -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE $PYTEST_TARGET" if [[ $(uname) != "Linux" && $(uname) != "Darwin" ]]; then PYTEST_CMD="$PYTEST_CMD --ignore=pandas/tests/plotting/" From 8e8fa7dc0bfd4f8c3e50b8553351e8bef3c7d00a Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Tue, 30 Nov 2021 16:54:55 -0800 Subject: [PATCH 17/17] Test that these ipython tests are the culprit --- pandas/tests/io/formats/test_printing.py | 27 ++++++++---------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/pandas/tests/io/formats/test_printing.py b/pandas/tests/io/formats/test_printing.py index f0d5ef19c4468..8e350831c192d 100644 --- a/pandas/tests/io/formats/test_printing.py +++ b/pandas/tests/io/formats/test_printing.py @@ -1,5 +1,4 @@ import numpy as np -import pytest import pandas._config.config as cf @@ -120,16 +119,8 @@ def test_ambiguous_width(self): class TestTableSchemaRepr: - @classmethod - def setup_class(cls): - pytest.importorskip("IPython") - - from IPython.core.interactiveshell import InteractiveShell - - cls.display_formatter = InteractiveShell.instance().display_formatter - - def test_publishes(self): - + def test_publishes(self, ip): + ipython = ip.instance(config=ip.config) df = pd.DataFrame({"A": [1, 2]}) objects = [df["A"], df, df] # dataframe / series expected_keys = [ @@ -140,13 +131,13 @@ def test_publishes(self): opt = pd.option_context("display.html.table_schema", True) for obj, expected in zip(objects, expected_keys): with opt: - formatted = self.display_formatter.format(obj) + formatted = ipython.display_formatter.format(obj) assert set(formatted[0].keys()) == expected with_latex = pd.option_context("display.latex.repr", True) with opt, with_latex: - formatted = self.display_formatter.format(obj) + formatted = ipython.display_formatter.format(obj) expected = { "text/plain", @@ -156,7 +147,7 @@ def test_publishes(self): } assert set(formatted[0].keys()) == expected - def test_publishes_not_implemented(self): + def test_publishes_not_implemented(self, ip): # column MultiIndex # GH 15996 midx = pd.MultiIndex.from_product([["A", "B"], ["a", "b", "c"]]) @@ -165,7 +156,7 @@ def test_publishes_not_implemented(self): opt = pd.option_context("display.html.table_schema", True) with opt: - formatted = self.display_formatter.format(df) + formatted = ip.instance(config=ip.config).display_formatter.format(df) expected = {"text/plain", "text/html"} assert set(formatted[0].keys()) == expected @@ -184,9 +175,9 @@ def test_config_default_off(self): assert result is None - def test_enable_data_resource_formatter(self): + def test_enable_data_resource_formatter(self, ip): # GH 10491 - formatters = self.display_formatter.formatters + formatters = ip.instance(config=ip.config).display_formatter.formatters mimetype = "application/vnd.dataresource+json" with pd.option_context("display.html.table_schema", True): @@ -202,4 +193,4 @@ def test_enable_data_resource_formatter(self): assert "application/vnd.dataresource+json" in formatters assert formatters[mimetype].enabled # smoke test that it works - self.display_formatter.format(cf) + ip.instance(config=ip.config).display_formatter.format(cf)