test: step 2 refactor towards idempotency #43612
Merged
+247
−294
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.
As with test: step 1 refactor towards idempotency #43610
test_records
may be considered an anti-pattern if it doesn't deviate from the default behaviour. Instead, we ensure proper dependency declaration, and useself.globalTestRecords
(actually:cls.globalTestRecords
)cc @ruthra-kumar @rohitwaghchaure @s-aga-r @deepeshgarg007
If we can get this to green, then this is a significant step, because it means that we have achived (or maybe only ensured, cause it already was the case) a baseline for a certain locality and isolation of tests: items inside
cls.globalTestRecords
are MappingProxys and therefore can't be written to. They represent the records at their time of insertion into the database. On a rerun on the CLI with the same database, they are reconstructed fromsites/test_site/.test_log.jsonl
instead of from an actual insert and represent the records at the time of their original insert on prior test runs.This PR also significantly reduces the deprecation warning pressure on CLI.
Intermediate Step Required
This is wonderful! It shows that the mapping proxies are working as intended. On the framework side, we want to modify at least
frappe.copy_doc
to work with MappingProxy, as of its widespread use in tests.enterClassContext
/enterContext
techniqueAll
frappe.tests.classes.context_managers
can be used insetUp
orsetUpClass
withenterContext
orenterClassContext
. This is a relatively new unittest feature which takes a context manager and ensures the context is upheld during the entire scope of the test class / test case respecitvely.An example of its use: c17de26
Further Intemediate Steps Required
These mainly fixed the Test Record loading for correctness. The most significant change was to load actual json records into
cls.globalTestRecords
instead ofdoc.as_dict()
post db-insertion. This matches more closely the expectations that test designers had when they previously declaredtest_records = ...
.