Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{Core} Fix: test_credscache_good_error_on_file_corruption fails when run in parallel with other tests #17477

Merged
merged 1 commit into from
Apr 6, 2021

Conversation

jiasli
Copy link
Member

@jiasli jiasli commented Mar 26, 2021

Symptom

Fix: test_credscache_good_error_on_file_corruption fails when run in parallel with other tests

CI failure:

https://dev.azure.com/azure-sdk/playground/_build/results?buildId=806624&view=logs&j=abe8eae2-a613-5a65-3eeb-3e8a13573181&t=ff49c02d-6a40-524c-c9b1-98f6bb13c7f4&l=2248

__________ TestProfile.test_credscache_good_error_on_file_corruption ___________
[gw0] linux -- Python 3.8.8 /home/vsts/work/1/s/env/bin/python
self = <azure.cli.core.tests.test_profile.TestProfile testMethod=test_credscache_good_error_on_file_corruption>
get_file_json_mock = <function get_file_json at 0x7f723502fee0>

    @mock.patch('azure.cli.core._profile.get_file_json', autospec=True)
    def test_credscache_good_error_on_file_corruption(self, get_file_json_mock):
        get_file_json_mock.side_effect = ValueError('a bad error for you')
        cli = DummyCli()
    
        # action
        creds_cache = CredsCache(cli, async_persist=False)
    
        # assert
        with self.assertRaises(CLIError) as context:
>           creds_cache.load_adal_token_cache()
E           AssertionError: CLIError not raised

src/azure-cli-core/azure/cli/core/tests/test_profile.py:1799: AssertionError

Root cause

The test test_credscache_good_error_on_file_corruption assumes ~/.azure/accessTokens.json exists when it is run. If there is no ~/.azure/accessTokens.json,

if os.path.isfile(file_path):

evaluates to False, thus bypassing the code under test, causing failure.

This can also be repoed by deleting ~/.azure/accessTokens.json and only running test_credscache_good_error_on_file_corruption:

pytest src/azure-cli-core/azure/cli/core/tests/test_profile.py::TestProfile::test_credscache_good_error_on_file_corruption -o log_cli_level=DEBUG

⚠ In parallel testing, the existence of ~/.azure/accessTokens.json is not guaranteed, so the failure.

Change

Also patch os.path.isfile to make the test isolated from the underlying file system.

@yonzhan
Copy link
Collaborator

yonzhan commented Mar 26, 2021

Core

@yonzhan yonzhan added this to the S185 milestone Mar 26, 2021
@jiasli jiasli merged commit 12be822 into Azure:dev Apr 6, 2021
@jiasli jiasli deleted the profile-test branch April 6, 2021 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants