Skip to content

Commit 275506f

Browse files
authored
fix: use faux_conn rather than engine in unit tests (#431)
Remove the engine fixture from unit tests and use faux_conn instead. Creating an engine requires credentials, which prevents these tests from being pure unit tests and running in any environment. Fixes #430 🦕
1 parent 934e25f commit 275506f

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

tests/unit/conftest.py

-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@
4242
)
4343

4444

45-
@pytest.fixture()
46-
def engine():
47-
return sqlalchemy.create_engine("bigquery://myproject/mydataset")
48-
49-
5045
@pytest.fixture()
5146
def faux_conn():
5247
test_data = dict(execute=[])

tests/unit/test__struct.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ def _col():
8080
),
8181
],
8282
)
83-
def test_struct_traversal_project(engine, expr, sql):
83+
def test_struct_traversal_project(faux_conn, expr, sql):
8484
sql = f"SELECT {sql} AS `anon_1` \nFROM `t`"
85-
assert str(sqlalchemy.select([expr]).compile(engine)) == sql
85+
assert str(sqlalchemy.select([expr]).compile(faux_conn.engine)) == sql
8686

8787

8888
@pytest.mark.parametrize(
@@ -113,13 +113,13 @@ def test_struct_traversal_project(engine, expr, sql):
113113
),
114114
],
115115
)
116-
def test_struct_traversal_filter(engine, expr, sql, param=1):
116+
def test_struct_traversal_filter(faux_conn, expr, sql, param=1):
117117
want = f"SELECT `t`.`person` \nFROM `t`, `t` \nWHERE {sql}"
118-
got = str(sqlalchemy.select([_col()]).where(expr).compile(engine))
118+
got = str(sqlalchemy.select([_col()]).where(expr).compile(faux_conn.engine))
119119
assert got == want
120120

121121

122-
def test_struct_insert_type_info(engine, metadata):
122+
def test_struct_insert_type_info(faux_conn, metadata):
123123
t = sqlalchemy.Table("t", metadata, sqlalchemy.Column("person", _test_struct()))
124124
got = str(
125125
t.insert()
@@ -129,7 +129,7 @@ def test_struct_insert_type_info(engine, metadata):
129129
children=[dict(name="billy", bdate=datetime.date(2020, 1, 1))],
130130
)
131131
)
132-
.compile(engine)
132+
.compile(faux_conn.engine)
133133
)
134134

135135
assert got == (
@@ -139,14 +139,14 @@ def test_struct_insert_type_info(engine, metadata):
139139
)
140140

141141

142-
def test_struct_non_string_field_access(engine):
142+
def test_struct_non_string_field_access(faux_conn):
143143
with pytest.raises(
144144
TypeError,
145145
match="STRUCT fields can only be accessed with strings field names, not 42",
146146
):
147147
_col()[42]
148148

149149

150-
def test_struct_bad_name(engine):
150+
def test_struct_bad_name(faux_conn):
151151
with pytest.raises(KeyError, match="42"):
152152
_col()["42"]

tests/unit/test_select.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,9 @@ def test_unnest_w_no_table_references(faux_conn, alias):
433433
)
434434

435435

436-
def test_array_indexing(engine, metadata):
436+
def test_array_indexing(faux_conn, metadata):
437437
t = sqlalchemy.Table(
438438
"t", metadata, sqlalchemy.Column("a", sqlalchemy.ARRAY(sqlalchemy.String)),
439439
)
440-
got = str(sqlalchemy.select([t.c.a[0]]).compile(engine))
440+
got = str(sqlalchemy.select([t.c.a[0]]).compile(faux_conn.engine))
441441
assert got == "SELECT `t`.`a`[OFFSET(%(a_1:INT64)s)] AS `anon_1` \nFROM `t`"

0 commit comments

Comments
 (0)