Replies: 2 comments
-
|
Proof of concept: This should work for both use cases above, though i've only tested it via |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Landed in 25ad943. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Building on the work done by @alexanderpetrenz I think we should add some tooling to help make sure you don't develop against stale reusable containers. (This only applies to reusable containers, by default they are always recreated anyway).
User Stories
image()fixture, for example to use postgres 14 and its new JSON syntax. Yougit pulland your tests start failing. Sometimes this might not be obvious and the breakage might be some time after the root cause.build()fixture. Right now thebuild()will still run. But the old container will be used.Proposal
Track staleness using labels. In the simplest case just do a
json.dumps()of kwargs before calling the underlying docker API. E.g.This might be too large to store on a label so it would be better to sha hash the JSON string (using sort_keys on json.dumps to make extra sure the hash is stable).
Now in reusable mode, after finding a matching container check if its stale. If it is stale, delete it and fall through to the no matching container case.
Edge cases
If this is applied to networks and volumes and we find that one is stale we might try to delete it when it is still used by a container. I believe in this case the right thing to do is enumerate containers generated by pytest-docker-tools and delete the ones that use this network or volume. Because pytest will be running the fixtures in dependency order the deleted containers should be recreated against the correct and updated network/volume in the next step.
Containers that are referenced by other containers are safe to delete. If container b references container a's ip address and container a is recreated, container b will be considered stale and recreated as well.
Alternatives
Beta Was this translation helpful? Give feedback.
All reactions