{Role} fix test fail when running in serial due to buggy way to swtich tempory folder back #13061
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When running these 2 tests in serial:
The second one will fail on Linux but succeed on Windows.
Why failed on Linux?
At the beginning, the 1st test would chdir to a temporary dir.
azure-cli/src/azure-cli/azure/cli/command_modules/role/tests/latest/test_role.py
Lines 351 to 354 in 280692d
and at the end the of test, it would try to switch back but actually it didn't because the
basr_diris a relative path. So, the original directory is lost and the test procedure would stay at the temporary directory.azure-cli/src/azure-cli/azure/cli/command_modules/role/tests/latest/test_role.py
Lines 369 to 372 in 280692d
However, during the creation of tempory directory, it will register a callback to clean this folder away after the test is done.
So, when the second test starts, it's in a non-existing directory, and the intialization of CLI instannce would fail due to LocalContext object require reading a file from current dir:
Why succeeded on Windows
The removal temporary dir is ignoring the permission error
If set ignore=False, you will see:

So, the deletion wouldn't succeed and the second test would stuck in that temporary folder and succeed just lucky.
Testing Guide
Before fix, run via
History Notes
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.