Skip to content

Commit

Permalink
test(duckdb): run test in subprocess to avoid setting the default bac…
Browse files Browse the repository at this point in the history
…kend
  • Loading branch information
cpcloud authored and kszucs committed Jan 29, 2024
1 parent 9638eeb commit 42050d1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.

This file was deleted.

31 changes: 21 additions & 10 deletions ibis/backends/duckdb/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import os
import subprocess
import sys

import duckdb
import pandas as pd
Expand Down Expand Up @@ -211,18 +213,27 @@ def test_insert_preserves_column_case(con):
assert t1.count().execute() == 8


def test_default_backend(snapshot):
df = pd.DataFrame({"a": [1, 2, 3]})
t = ibis.memtable(df)
expr = t.a.sum()
def test_default_backend():
# use subprocess to avoid mutating state across tests
script = """\
import pandas as pd
import ibis
# run this twice to ensure that we hit the optimizations in
# `_default_backend`
for _ in range(2):
assert expr.execute() == df.a.sum()
df = pd.DataFrame({"a": [1, 2, 3]})
sql = ibis.to_sql(expr)
snapshot.assert_match(sql, "out.sql")
t = ibis.memtable(df)
expr = t.a.sum()
# run twice to ensure that we hit the optimizations in
# `_default_backend`
for _ in range(2):
assert expr.execute() == df.a.sum()"""

assert ibis.options.default_backend is None
subprocess.run([sys.executable, "-c", script], check=True)
assert ibis.options.default_backend is None


@pytest.mark.parametrize(
Expand Down

0 comments on commit 42050d1

Please sign in to comment.