6
6
import contextlib
7
7
import enum
8
8
import functools
9
+ import inspect
9
10
import itertools
10
11
import operator
11
12
import os
@@ -853,6 +854,16 @@ def release_lock() -> None:
853
854
854
855
extra_run_args .append (f"--cidfile={ self ._cidfile } " )
855
856
857
+ # Create a copy of the container which was used to parametrize this test
858
+ cls = type (self .container )
859
+ constructor = inspect .signature (cls .__init__ )
860
+ constructor .parameters
861
+
862
+ kwargs = {
863
+ k : v
864
+ for k , v in self .container .__dict__ .items ()
865
+ if k in constructor .parameters
866
+ }
856
867
# We must perform the launches in separate branches, as containers with
857
868
# port forwards must be launched while the lock is being held. Otherwise
858
869
# another container could pick the same ports before this one launches.
@@ -864,20 +875,26 @@ def release_lock() -> None:
864
875
for new_forward in self ._new_port_forwards :
865
876
extra_run_args += new_forward .forward_cli_args
866
877
867
- launch_cmd = self .container .get_launch_cmd (
878
+ kwargs ["forwarded_ports" ] = self ._new_port_forwards
879
+ ctr = cls (** kwargs )
880
+
881
+ launch_cmd = ctr .get_launch_cmd (
868
882
self .container_runtime , extra_run_args = extra_run_args
869
883
)
870
884
871
885
_logger .debug ("Launching container via: %s" , launch_cmd )
872
886
check_output (launch_cmd )
873
887
else :
874
- launch_cmd = self .container .get_launch_cmd (
888
+ ctr = cls (** kwargs )
889
+ launch_cmd = ctr .get_launch_cmd (
875
890
self .container_runtime , extra_run_args = extra_run_args
876
891
)
877
892
878
893
_logger .debug ("Launching container via: %s" , launch_cmd )
879
894
check_output (launch_cmd )
880
895
896
+ self .container = ctr
897
+
881
898
with open (self ._cidfile , "r" , encoding = "utf8" ) as cidfile :
882
899
self ._container_id = cidfile .read (- 1 ).strip ()
883
900
0 commit comments