diff --git a/lite_bootstrap/bootstrappers/base.py b/lite_bootstrap/bootstrappers/base.py index 938c251..c690e25 100644 --- a/lite_bootstrap/bootstrappers/base.py +++ b/lite_bootstrap/bootstrappers/base.py @@ -74,6 +74,8 @@ def _prepare_application(self) -> ApplicationT: ... def is_ready(self) -> bool: ... def bootstrap(self) -> ApplicationT: + if self.is_bootstrapped: + return self._prepare_application() self.is_bootstrapped = True for one_instrument in self.instruments: one_instrument.bootstrap() diff --git a/tests/test_free_bootstrap.py b/tests/test_free_bootstrap.py index c097a62..0157c77 100644 --- a/tests/test_free_bootstrap.py +++ b/tests/test_free_bootstrap.py @@ -124,3 +124,18 @@ def test_teardown_is_idempotent(free_bootstrapper_config: FreeConfig) -> None: first.teardown.assert_called_once() second.teardown.assert_called_once() assert not bootstrapper.is_bootstrapped + + +def test_bootstrap_is_idempotent(free_bootstrapper_config: FreeConfig) -> None: + bootstrapper = FreeBootstrapper(bootstrap_config=free_bootstrapper_config) + + first = MagicMock() + second = MagicMock() + bootstrapper.instruments = [first, second] + + bootstrapper.bootstrap() + bootstrapper.bootstrap() + + first.bootstrap.assert_called_once() + second.bootstrap.assert_called_once() + assert bootstrapper.is_bootstrapped