_hypothesis_globals.py 1.2 KB

12345678910111213141516171819202122232425262728
  1. # This file is part of Hypothesis, which may be found at
  2. # https://github.com/HypothesisWorks/hypothesis/
  3. #
  4. # Copyright the Hypothesis Authors.
  5. # Individual contributors are listed in AUTHORS.rst and the git log.
  6. #
  7. # This Source Code Form is subject to the terms of the Mozilla Public License,
  8. # v. 2.0. If a copy of the MPL was not distributed with this file, You can
  9. # obtain one at https://mozilla.org/MPL/2.0/.
  10. """
  11. Module for globals shared between plugin(s) and the main hypothesis module, without
  12. depending on either. This file should have no imports outside of stdlib.
  13. """
  14. import os
  15. in_initialization = 1
  16. """If >0, indicates that hypothesis is still initializing (importing or loading
  17. the test environment). `import hypothesis` will cause this number to be decremented,
  18. and the pytest plugin increments at load time, then decrements it just before each test
  19. session starts. However, this leads to a hole in coverage if another pytest plugin
  20. imports hypothesis before our plugin is loaded. HYPOTHESIS_EXTEND_INITIALIZATION may
  21. be set to pre-increment the value on behalf of _hypothesis_pytestplugin, plugging the
  22. hole."""
  23. if os.environ.get("HYPOTHESIS_EXTEND_INITIALIZATION"):
  24. in_initialization += 1