Test script caching
To be reliable, tests must be consistent and repeatable. To ensure this, the SDK will cache the results of successful extractions into a test script that can be reused in subsequent test runs.
Customizing the cache directory
You can configure the location of the cache directory by changing the cache_dir
parameter:
self.carbonate_sdk = carbonate.SDK(
# ...
# This will store the files in a directory named after the test file
cache_dir=os.path.join(os.path.splitext(__file__)[0]),
)
This directory, and the resulting cached test scripts, should be committed to your source control system.
Invalidating the cache
When you change your HTML significantly, your tests will start to fail since the tests are testing the old HTML. If this is expected, you can invalidate the cache by deleting the appropriate directory. This will force the SDK to re-extract a new test script the next time it is run.
Invalidating the cache of an entire test case
For example, if you wish to invalidate the cache for the tests contained within test/test_my_test.py
, you should delete the test/test_my_test
directory:
rm -rf test/test_my_test
Invalidating the cache of a single test
If you only wish to invalidate a single test and not the entire test case, you can delete the sub-directory that matches your test name.
For example, if you wish to invalidate the cache for the it_should_do_my_action
test, you should delete the test/test_my_test/it_should_do_my_action
directory:
rm -rf test/test_my_test/test_it_should_do_my_action
Real-world example
You can find an example of what the cache structure looks like by looking at the internal SDK tests.