Skip to content

Commit

Permalink
fix: make DB connection a function-scope fixture
Browse files Browse the repository at this point in the history
Many tests use a DuckDB connection as a fixture. That fixture was set to
a `class` scope, such that a DuckDB connection was created only once for
all tests of a particular class, presumably to speed up tests. However,
tests may corrupt the DuckDB instance, making all subsequent tests fail
as a result. This lack of reproducibility undermines tests and is far
worse than slightly longer-running tests. This PR thus makes all
mentioned fixtures function-scoped (by removing the `scope` definition,
`function` scope is the default).

Signed-off-by: Ingo Müller <[email protected]>
  • Loading branch information
ingomueller-net committed Nov 28, 2024
1 parent 915c889 commit 1c2b8e0
Show file tree
Hide file tree
Showing 24 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions substrait_consumer/tests/adhoc/test_adhoc_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class TestAdhocExpression:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls
cls.produced_plans = set()

@staticmethod
@pytest.fixture(scope="function", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_function(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TestApproximationFunctions:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TestArithmeticDecimalFunctions:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class TestArithmeticFunctions:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestBooleanFunctions:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TestComparisonFunctions:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TestDatetimeFunctions:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TestLogarithmicFunctions:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TestRoundingFunctions:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TestStringFunctions:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TestSubstraitFunctionNames:
"""

@staticmethod
@pytest.fixture(scope="function", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_function(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestAggregatetRelation:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TestDDLRelation:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestFetchRelation:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TestfilterRelation:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TestJoinRelation:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TestProjectRelation:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestReadRelation:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestSetRelation:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestSortRelation:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TestWriteRelation:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
2 changes: 1 addition & 1 deletion substrait_consumer/tests/integration/test_acero_tpch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TestAceroConsumer:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls
cls.db_connection = duckdb.connect()
Expand Down
2 changes: 1 addition & 1 deletion substrait_consumer/tests/integration/test_duckdb_tpch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TestDuckDBConsumer:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TestTpchPlansValid:
"""

@staticmethod
@pytest.fixture(scope="class", autouse=True)
@pytest.fixture(autouse=True)
def setup_teardown_class(request):
cls = request.cls
cls.db_connection = duckdb.connect()
Expand Down

0 comments on commit 1c2b8e0

Please sign in to comment.