Skip to content

Commit 2a335be

Browse files
SNOW-999576: Fix several local test problems (#1846)
* Dig `warehouse` out of db_parameters for tests that require it * Fix an assumption that ~/.snowflake doesn't exist * Add a changelog * We don't need tox-external-wheels; tox 4 supports this natively * Slightly better test docs * Eliminate file leakage in unit test Also, fix some comment characters in tox.ini, and add a README note about potential failures for integration tests run against certain cloud providers.
1 parent 93c9b69 commit 2a335be

File tree

9 files changed

+41
-25
lines changed

9 files changed

+41
-25
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
1313
- Added a new boolean parameter `force_return_table` to `SnowflakeCursor.fetch_arrow_all` to force returning `pyarrow.Table` in case of zero rows.
1414
- Cleanup some C++ code warnings and performance issues.
1515
- Added support for Python 3.12
16+
- Make local testing more robust against implicit assumptions.
1617

1718
- v3.6.0(December 09,2023)
1819

test/README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,35 @@ CONNECTION_PARAMETERS = {
1414
}
1515
```
1616

17-
### Running a single test
18-
19-
Assuming that all dependencies are installed, running a single test is as simple as:
20-
`python -m pytest test/integ/test_connection.py::test_basic`.
21-
2217
### Running a suite of tests
2318

24-
We use `tox` to run test suites and other utilities.
19+
We use `tox` version 4 to run test suites and other utilities.
2520

2621
To run the most important tests, execute:
2722

2823
```shell
2924
tox -e "fix_lint,py37{,-pandas,-sso}"
3025
```
3126

27+
**NOTE** Some integration tests may be sensitive to the cloud provider of the
28+
account that the test suite connects to. By default, when testing locally,
29+
the "provider" is called `dev`, but you may see some test failures with this
30+
provider (which isn't really a provider). To eliminate this false failure,
31+
set the environment variable `cloud_provider` to one of `aws`, `gcp`, or
32+
`azure` as appropriate for the account you're running integration tests
33+
against. This is handled correctly in CI so should only affect local
34+
developers. In the future, we'll try to make this automatic by querying the
35+
account after the connection is made.
36+
37+
### Running a single test
38+
39+
Enter the tox environment you want (e.g. `py38`) and run `pytest` from there:
40+
41+
```shell
42+
source .tox/py38/bin/activate
43+
pytest -v test/integ/test_connection.py::test_basic
44+
```
45+
3246
## Test types
3347
These test types can be mixed with test categories, or with each other.
3448
Note: providing both to tox runs both integration and unit tests of the current category and not providing

test/integ/test_autocommit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def exe(cnx, sql):
167167
protocol=db_parameters["protocol"],
168168
schema=db_parameters["schema"],
169169
database=db_parameters["database"],
170+
warehouse=db_parameters["warehouse"],
170171
autocommit=False,
171172
) as cnx:
172173
exe(
@@ -186,6 +187,7 @@ def exe(cnx, sql):
186187
protocol=db_parameters["protocol"],
187188
schema=db_parameters["schema"],
188189
database=db_parameters["database"],
190+
warehouse=db_parameters["warehouse"],
189191
autocommit=True,
190192
) as cnx:
191193
_run_autocommit_on(cnx, db_parameters)

test/integ/test_converter_null.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def test_converter_no_converter_to_python(db_parameters):
2727
port=db_parameters["port"],
2828
account=db_parameters["account"],
2929
database=db_parameters["database"],
30+
warehouse=db_parameters["warehouse"],
3031
schema=db_parameters["schema"],
3132
protocol=db_parameters["protocol"],
3233
timezone="UTC",

test/integ/test_cursor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ def test_insert_timestamp_select(conn, db_parameters):
297297
account=db_parameters["account"],
298298
database=db_parameters["database"],
299299
schema=db_parameters["schema"],
300+
warehouse=db_parameters["warehouse"],
300301
protocol=db_parameters["protocol"],
301302
timezone="UTC",
302303
)

test/integ/test_transaction.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def test_connection_context_manager(request, db_parameters):
7878
"host": db_parameters["host"],
7979
"port": db_parameters["port"],
8080
"database": db_parameters["database"],
81+
"warehouse": db_parameters["warehouse"],
8182
"schema": db_parameters["schema"],
8283
"timezone": "UTC",
8384
}

test/unit/test_configmanager.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,14 @@ def test_config_file_resolution_sfdirs_nondefault(tmp_path, monkeypatch):
530530
assert isinstance(_resolve_platform_dirs(), SFPlatformDirs)
531531

532532

533-
def test_config_file_resolution_non_sfdirs(monkeypatch):
533+
def test_config_file_resolution_non_sfdirs(tmp_path, monkeypatch):
534534
with monkeypatch.context() as m:
535-
m.delenv("SNOWFLAKE_HOME", raising=False)
535+
# 2024-01-03(bwarsaw): It's not enough to remove SNOWFLAKE_HOME from the environment, because
536+
# _resolve_platform_dirs() defaults to ~/.snowflake, so if the user running the tests has this
537+
# directory, the test will fail. Instead, ensure that this environment variable points to a
538+
# non-existent directory.
539+
fake_home = tmp_path / ".snowflake"
540+
m.setenv("SNOWFLAKE_HOME", str(fake_home))
536541
assert not isinstance(_resolve_platform_dirs(), SFPlatformDirs)
537542

538543

test/unit/test_encryption_util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ def test_encrypt_decrypt_file(tmp_path):
4343
fd.write(data)
4444

4545
(metadata, encrypted_file) = SnowflakeEncryptionUtil.encrypt_file(
46-
encryption_material, input_file
46+
encryption_material, input_file, tmp_dir=str(tmp_path)
4747
)
4848
decrypted_file = SnowflakeEncryptionUtil.decrypt_file(
49-
metadata, encryption_material, encrypted_file
49+
metadata, encryption_material, encrypted_file, tmp_dir=str(tmp_path)
5050
)
5151

5252
contents = ""
@@ -98,10 +98,10 @@ def test_encrypt_decrypt_large_file(tmpdir):
9898
)
9999

100100
(metadata, encrypted_file) = SnowflakeEncryptionUtil.encrypt_file(
101-
encryption_material, input_file
101+
encryption_material, input_file, tmp_dir=str(tmpdir)
102102
)
103103
decrypted_file = SnowflakeEncryptionUtil.decrypt_file(
104-
metadata, encryption_material, encrypted_file
104+
metadata, encryption_material, encrypted_file, tmp_dir=str(tmpdir)
105105
)
106106

107107
digest_dec, size_dec = SnowflakeFileUtil.get_digest_and_size_for_file(

tox.ini

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,14 @@ envlist = fix_lint,
2121
py{37,38,39,310,311,312}-{extras,unit-parallel,integ,pandas,sso},
2222
coverage
2323
skip_missing_interpreters = true
24-
requires =
25-
tox-external-wheels>=0.1.6
2624

2725
[testenv]
2826
description = run the tests with pytest under {basepython}
2927
extras =
3028
development
3129
pandas: pandas
3230
sso: secure-local-storage
33-
install_command = python -m pip install -U {opts} {packages}
34-
external_wheels =
35-
py37-ci: dist/*cp37*.whl
36-
py38-ci: dist/*cp38*.whl
37-
py39-ci: dist/*cp39*.whl
38-
py310-ci: dist/*cp310*.whl
39-
py311-ci: dist/*cp311*.whl
40-
py312-ci: dist/*cp312*.whl
31+
package = wheel
4132
setenv =
4233
COVERAGE_FILE = {env:COVERAGE_FILE:{toxworkdir}/.coverage.{envname}}
4334
ci: SNOWFLAKE_PYTEST_OPTS = -vvv
@@ -58,11 +49,11 @@ passenv =
5849
SF_PROJECT_ROOT
5950
cloud_provider
6051
SF_REGRESS_LOGS
61-
; Github Actions provided environmental variables
52+
# Github Actions provided environmental variables
6253
GITHUB_ACTIONS
6354
JENKINS_HOME
64-
; This is required on windows. Otherwise pwd module won't be imported successfully,
65-
; see https://github.com/tox-dev/tox/issues/1455
55+
# This is required on windows. Otherwise pwd module won't be imported successfully,
56+
# see https://github.com/tox-dev/tox/issues/1455
6657
USERNAME
6758
CLIENT_LOG_DIR_PATH_DOCKER
6859
PYTEST_ADDOPTS

0 commit comments

Comments
 (0)