[unittest] supported condititonal testing based on env var #1701
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.
What is the problem?
During development, we often need to temporarily skip some tests, either because they take too long or they are currently not working well. However, we can easily forget that these tests are in fact required to verify the correctness of each commit. To solve this problem, skipping a test should be controlled by a condition. Before we put up a pull request to the GitHub, we can set the condition flag locally and run a full range test without manually removing
pytest.mark.skip
in the code.What does this PR do?
This PR added a util function
run_on_environment_flag
tocolossalai.testing
. This function receives a environment variable name and check if it is set to'1'
. If so, this test is executed, otherwise skipped.This PR also replaced
pytest.mark.skip
withrun_on_environment_flag
for theauto_parallel
module testing.Demo
# if you do not set AUTO_PARALLEL, it is the same AUTO_PARALLEL=0 pytest tests/test_auto_parallel/