Add make test_with_lazy_imports to allow users run the test suite with Lazy Imports
Add @unittest.skipIfLazyImportsIsDisabled for skipping some tests when Lazy Imports is disabled
Add @unittest.skipIfLazyImportsIsEnabled for skipping some tests when Lazy Imports is enabled
Add Lib/test/test_lazy_imports.py to validate this framework
Test Plan
Notes:
All these tests were executed in cinder/3.10.
This is a crashy branch, so somethings might not work here.
1. Test the behavior in test_lazy_imports.py
We will cover the testing of these four features in this section.
@unittest.skipIfLazyImportsIsDisabled
@unittest.skipIfLazyImportsIsEnabled
importlib.is_lazy_imports_enabled()
test_lazy_imports.py
When I remove @unittest.skipIfLazyImportsIsDisabled (line 8) and @unittest.skipIfLazyImportsIsEnabled (line 12) in test_lazy_imports.py, no matter this test is executed with or without Lazy Imports, the unit test will fail.
With Lazy Imports
Run
./python -L -m test test_lazy_imports
Expected results
It will fail in test_lazy_imports_is_disabled because Lazy Imports is enabled.
Without Lazy Imports
Run
./python -m test test_lazy_imports
Expected results
It will fail in test_lazy_imports_is_enabled because Lazy Imports is not enabled.
When I add @unittest.skipIfLazyImportsIsDisabled (line 8) and @unittest.skipIfLazyImportsIsEnabled (line 12) into test_lazy_imports.py, the unit test can be passed with or without Lazy Imports.
(same as the original test_lazy_imports.py )
With Lazy Imports
Run
./python -L -m test test_lazy_imports
Expected results
Without Lazy Imports
Run
./python -m test test_lazy_imports
Expected results
2. Test the framework
We add a new target, test_with_lazy_imports, in Makefile, so that we can easily validate the test suite with Lazy Imports by using make test_with_lazy_imports.
Test suite with Lazy Imports
If we run make test_with_lazy_imports, we would like to make every testing execute with Lazy Imports. To validate this, I remove some code in test_lazy_imports.py. We only leave test_lazy_imports_is_enabled.
Then, we can observe if it still can pass test_lazy_imports.py.
If it passes, all the tests are executed with Lazy Imports. Otherwise, make test_with_lazy_imports failed.
Run
make test_with_lazy_imports
Expected results
We expected test_lazy_imports did not fail during the validation. That is, it didn't show in the tests failed list.
Test suite without Lazy Imports
This test suite existed in the code. We could use make test to execute it, and the results should be the same as before.
Summary
importlib.is_lazy_imports_enabled
make test_with_lazy_imports
to allow users run the test suite with Lazy Imports@unittest.skipIfLazyImportsIsDisabled
for skipping some tests when Lazy Imports is disabled@unittest.skipIfLazyImportsIsEnabled
for skipping some tests when Lazy Imports is enabledLib/test/test_lazy_imports.py
to validate this frameworkTest Plan
1. Test the behavior in
test_lazy_imports.py
We will cover the testing of these four features in this section.
@unittest.skipIfLazyImportsIsDisabled
@unittest.skipIfLazyImportsIsEnabled
importlib.is_lazy_imports_enabled()
test_lazy_imports.py
When I remove
@unittest.skipIfLazyImportsIsDisabled
(line 8) and@unittest.skipIfLazyImportsIsEnabled
(line 12) intest_lazy_imports.py
, no matter this test is executed with or without Lazy Imports, the unit test will fail.With Lazy Imports
Run
Expected results
It will fail in
test_lazy_imports_is_disabled
because Lazy Imports is enabled.Without Lazy Imports
Run
Expected results It will fail in
test_lazy_imports_is_enabled
because Lazy Imports is not enabled.When I add
@unittest.skipIfLazyImportsIsDisabled
(line 8) and@unittest.skipIfLazyImportsIsEnabled
(line 12) intotest_lazy_imports.py
, the unit test can be passed with or without Lazy Imports.(same as the original
test_lazy_imports.py
)With Lazy Imports
Run
Expected results
Without Lazy Imports
Run
Expected results
2. Test the framework
We add a new target,
test_with_lazy_imports
, inMakefile
, so that we can easily validate the test suite with Lazy Imports by usingmake test_with_lazy_imports
.Test suite with Lazy Imports
If we run
make test_with_lazy_imports
, we would like to make every testing execute with Lazy Imports. To validate this, I remove some code intest_lazy_imports.py
. We only leavetest_lazy_imports_is_enabled
.Then, we can observe if it still can pass
test_lazy_imports.py
. If it passes, all the tests are executed with Lazy Imports. Otherwise,make test_with_lazy_imports
failed.Run
Expected results We expected
test_lazy_imports
did not fail during the validation. That is, it didn't show in the tests failed list.Test suite without Lazy Imports
This test suite existed in the code. We could use
make test
to execute it, and the results should be the same as before.