diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_samples.py b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_samples.py index 7e30f070c346..2c282f1976cd 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_samples.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_samples.py @@ -25,8 +25,6 @@ from azure.ai.formrecognizer import FormTrainingClient from testcase import FormRecognizerTest, GlobalFormRecognizerAccountPreparer -def _setenv(key, val): - os.environ[key] = os.getenv(val) or os.getenv(key) def run(cmd, my_env): os.environ['PYTHONUNBUFFERED'] = "1" @@ -45,21 +43,24 @@ def _test_file(file_name, account, key, root_dir='./samples'): my_env = dict(os.environ) if sys.version_info < (3, 5): my_env = {key: str(val) for key, val in my_env.items()} - code, _, err = run([sys.executable, root_dir + '/' + file_name], my_env=my_env) - assert code == 0 - assert err is None + code, out, err = run([sys.executable, root_dir + '/' + file_name], my_env=my_env) + try: + assert code == 0 + assert err is None + except AssertionError as e: + e.args += (out, ) + raise AssertionError(e) class TestSamples(FormRecognizerTest): @pytest.mark.live_test_only @GlobalFormRecognizerAccountPreparer() def test_sample_authentication(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): - _setenv('AZURE_FORM_RECOGNIZER_AAD_ENDPOINT', 'AZURE_FORM_RECOGNIZER_AAD_ENDPOINT') _test_file('sample_authentication.py', form_recognizer_account, form_recognizer_account_key) @pytest.mark.live_test_only @GlobalFormRecognizerAccountPreparer() def test_sample_get_bounding_boxes(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): - _setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL') + os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL") ftc = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key)) container_sas_url = os.environ['CONTAINER_SAS_URL'] poller = ftc.begin_training(container_sas_url, use_training_labels=False) @@ -80,7 +81,7 @@ def test_sample_recognize_content(self, resource_group, location, form_recognize @pytest.mark.live_test_only @GlobalFormRecognizerAccountPreparer() def test_sample_recognize_custom_forms(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): - _setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL') + os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL") ftc = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key)) container_sas_url = os.environ['CONTAINER_SAS_URL'] poller = ftc.begin_training(container_sas_url, use_training_labels=False) @@ -101,11 +102,11 @@ def test_sample_recognize_receipts(self, resource_group, location, form_recogniz @pytest.mark.live_test_only @GlobalFormRecognizerAccountPreparer() def test_sample_train_model_with_labels(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): - _setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL') + os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL") _test_file('sample_train_model_with_labels.py', form_recognizer_account, form_recognizer_account_key) @pytest.mark.live_test_only @GlobalFormRecognizerAccountPreparer() def test_sample_train_model_without_labels(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): - _setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL') + os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL") _test_file('sample_train_model_without_labels.py', form_recognizer_account, form_recognizer_account_key) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_samples_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_samples_async.py index d1db2ca048b4..88c74dfef491 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_samples_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/tests/test_samples_async.py @@ -24,9 +24,6 @@ from azure.ai.formrecognizer.aio import FormTrainingClient from testcase import FormRecognizerTest, GlobalFormRecognizerAccountPreparer -def _setenv(key, val): - os.environ[key] = os.getenv(val) or os.getenv(key) - def run(cmd, my_env): os.environ['PYTHONUNBUFFERED'] = "1" proc = subprocess.Popen(cmd, @@ -41,9 +38,13 @@ def run(cmd, my_env): def _test_file(file_name, account, key, root_dir='./samples/async_samples'): os.environ['AZURE_FORM_RECOGNIZER_ENDPOINT'] = account os.environ['AZURE_FORM_RECOGNIZER_KEY'] = key - code, _, err = run([sys.executable, root_dir + '/' + file_name], my_env=dict(os.environ)) - assert code == 0 - assert err is None + code, out, err = run([sys.executable, root_dir + '/' + file_name], my_env=dict(os.environ)) + try: + assert code == 0 + assert err is None + except AssertionError as e: + e.args += (out, ) + raise AssertionError(e) class TestSamplesAsync(FormRecognizerTest): @@ -56,7 +57,7 @@ def test_sample_authentication_async(self, resource_group, location, form_recogn @pytest.mark.live_test_only @GlobalFormRecognizerAccountPreparer() async def test_sample_get_bounding_boxes_async(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): - _setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL') + os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL") ftc = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key)) container_sas_url = os.environ['CONTAINER_SAS_URL'] poller = await ftc.begin_training(container_sas_url, use_training_labels=False) @@ -77,7 +78,7 @@ def test_sample_recognize_content_async(self, resource_group, location, form_rec @pytest.mark.live_test_only @GlobalFormRecognizerAccountPreparer() async def test_sample_recognize_custom_forms_async(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): - _setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL') + os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL") ftc = FormTrainingClient(form_recognizer_account, AzureKeyCredential(form_recognizer_account_key)) container_sas_url = os.environ['CONTAINER_SAS_URL'] poller = await ftc.begin_training(container_sas_url, use_training_labels=False) @@ -98,12 +99,12 @@ def test_sample_recognize_receipts_async(self, resource_group, location, form_re @pytest.mark.live_test_only @GlobalFormRecognizerAccountPreparer() def test_sample_train_model_with_labels_async(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): - _setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL') + os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL") _test_file('sample_train_model_with_labels_async.py', form_recognizer_account, form_recognizer_account_key) @pytest.mark.live_test_only @GlobalFormRecognizerAccountPreparer() def test_sample_train_model_without_labels_async(self, resource_group, location, form_recognizer_account, form_recognizer_account_key): - _setenv('CONTAINER_SAS_URL', 'AZURE_FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL') + os.environ['CONTAINER_SAS_URL'] = self.get_settings_value("FORM_RECOGNIZER_STORAGE_CONTAINER_SAS_URL") _test_file('sample_train_model_without_labels_async.py', form_recognizer_account, form_recognizer_account_key)