Skip to content

Commit b08e8ca

Browse files
author
Elliot Boschwitz
authored
Add support for unstable unit tests (#382)
* Added pytest marks for unstable tests * Added new build function to call unstable tests
1 parent 504e900 commit b08e8ca

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

build.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,23 @@ def unit_test():
126126
"""
127127
runid = str(uuid.uuid1())
128128
python_version = platform.python_version()
129-
utility.exec_command(
130-
'pytest -l --cov mssqlcli --doctest-modules --junitxml=junit/test-{}-results.xml \
131-
--cov-report=xml --cov-report=html --cov-append '
132-
'-o junit_suite_name=pytest-{} '
129+
utility.exec_command(('pytest -l --cov mssqlcli --doctest-modules '
130+
'--junitxml=junit/test-{}-results.xml --cov-report=xml '
131+
'--cov-report=html --cov-append -o junit_suite_name=pytest-{} '
132+
'-s -m "not unstable" {}').format(runid, python_version,
133+
get_active_test_filepaths()),
134+
utility.ROOT_DIR, continue_on_error=False)
135+
136+
def unstable_unit_test():
137+
"""
138+
Run all unstable unit tests.
139+
"""
140+
utility.exec_command('pytest -s -v -m unstable {}'.format(get_active_test_filepaths()),
141+
utility.ROOT_DIR, continue_on_error=False)
142+
143+
144+
def get_active_test_filepaths():
145+
return (
133146
'tests/test_mssqlcliclient.py '
134147
'tests/test_completion_refresher.py '
135148
'tests/test_config.py '
@@ -143,10 +156,9 @@ def unit_test():
143156
'tests/test_telemetry.py '
144157
'tests/test_localization.py '
145158
'tests/test_globalization.py '
146-
'-s tests/test_noninteractive_mode.py '# -s disables capturing--test doesn't work without it
147-
'tests/test_special.py'.format(runid, python_version),
148-
utility.ROOT_DIR,
149-
continue_on_error=False)
159+
'tests/test_noninteractive_mode.py '
160+
'tests/test_special.py'
161+
)
150162

151163

152164
def integration_test():
@@ -223,6 +235,7 @@ def create_dir(path):
223235
'build': build,
224236
'validate_package': validate_package,
225237
'unit_test': unit_test,
238+
'unstable_unit_test': unstable_unit_test,
226239
'integration_test': integration_test,
227240
'test': test
228241
}

tests/jsonrpc/test_jsonrpcclient.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import time
33
import io
44
import threading
5-
5+
import pytest
66
import mssqlcli.jsonrpc.jsonrpcclient as json_rpc_client
77

88

@@ -170,6 +170,7 @@ def test_send_invalid_request(self):
170170
with self.assertRaises(ValueError):
171171
test_client.submit_request(None, None)
172172

173+
@pytest.mark.unstable
173174
def test_receive_invalid_response_exception(self):
174175
"""
175176
Verify invalid response has exception queued and response thread dies.

tests/test_globalization.py

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def test_db():
172172
yield db
173173
clean_up_test_db(db)
174174

175+
@pytest.mark.unstable
175176
def test_schema_metadata_double(self, test_db):
176177
self.run_schema_metadata_validation('double', test_db)
177178

tests/test_mssqlcliclient.py

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def test_get_query_results(client):
119119
assert query == test_query
120120

121121
@staticmethod
122+
@pytest.mark.unstable
122123
def test_schema_table_views_and_columns_query(client):
123124
"""
124125
Verify mssqlcliclient's tables, views, columns, and schema are populated.
@@ -160,6 +161,7 @@ def drop_entities(mssqlcli_client):
160161
drop_entities(client)
161162

162163
@staticmethod
164+
@pytest.mark.unstable
163165
def test_stored_proc_multiple_result_sets(client):
164166
"""
165167
Verify the results of running a stored proc with multiple result sets

utility.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from subprocess import check_call, CalledProcessError
33
import os
44
import platform
5+
import shlex
56
import shutil
67
import sys
78
import string
@@ -21,7 +22,12 @@ def exec_command(command, directory, continue_on_error=True):
2122
Execute command.
2223
"""
2324
try:
24-
check_call(command.split(), cwd=directory)
25+
command_split = [token.strip('"') for token in shlex.split(command, posix=False)]
26+
# The logic above is used to preserve multiple token arguments with pytest. It is
27+
# specifically needed when calling "not unstable" for running all tests not marked
28+
# as unstable.
29+
30+
check_call(command_split, cwd=directory)
2531
except CalledProcessError as err:
2632
# Continue execution in scenarios where we may be bulk command execution.
2733
print(err, file=sys.stderr)

0 commit comments

Comments
 (0)