|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +import traceback |
| 16 | + |
15 | 17 | import pandas as pd |
16 | 18 | import pytest |
17 | 19 |
|
|
20 | 22 | pytest.importorskip("anywidget") |
21 | 23 |
|
22 | 24 |
|
| 25 | +@pytest.fixture(scope="module", autouse=True) |
| 26 | +def cleanup_session(session): |
| 27 | + """Ensure comprehensive cleanup happens after all tests in this module.""" |
| 28 | + yield |
| 29 | + try: |
| 30 | + # Force cleanup of anonymous dataset and all temporary tables |
| 31 | + if hasattr(session, "_anon_dataset_manager") and session._anon_dataset_manager: |
| 32 | + session._anon_dataset_manager.close() |
| 33 | + |
| 34 | + # Also call the main session cleanup |
| 35 | + session.close() |
| 36 | + except Exception as e: |
| 37 | + traceback.print_exception(type(e), e, None) |
| 38 | + # Try the BigFrames cleanup function as fallback |
| 39 | + try: |
| 40 | + import bigframes.pandas as bpd |
| 41 | + |
| 42 | + bpd.clean_up_by_session_id( |
| 43 | + session.session_id, location=session._location, project=session._project |
| 44 | + ) |
| 45 | + except Exception as cleanup_error: |
| 46 | + print(f"Warning: Fallback cleanup also failed: {cleanup_error}") |
| 47 | + traceback.print_exception(type(cleanup_error), cleanup_error, None) |
| 48 | + |
| 49 | + |
23 | 50 | @pytest.fixture(scope="module") |
24 | 51 | def paginated_pandas_df() -> pd.DataFrame: |
25 | 52 | """Create a test DataFrame with exactly 3 pages of manually defined data.""" |
@@ -88,18 +115,6 @@ def table_widget(paginated_bf_df: bf.dataframe.DataFrame): |
88 | 115 | return widget |
89 | 116 |
|
90 | 117 |
|
91 | | -@pytest.fixture(scope="module", autouse=True) |
92 | | -def cleanup_session(session): |
93 | | - """Ensure session cleanup happens after all tests in this module.""" |
94 | | - yield |
95 | | - # Force cleanup of all temporary resources if session is still active |
96 | | - try: |
97 | | - session.close() |
98 | | - except Exception: |
99 | | - # Session may already be closed by the global fixture |
100 | | - pass |
101 | | - |
102 | | - |
103 | 118 | def _assert_html_matches_pandas_slice( |
104 | 119 | table_html: str, |
105 | 120 | expected_pd_slice: pd.DataFrame, |
|
0 commit comments