setupplan.py 891 B

1234567891011121314151617181920212223242526272829303132
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import
  3. from __future__ import division
  4. from __future__ import print_function
  5. import pytest
  6. def pytest_addoption(parser):
  7. group = parser.getgroup("debugconfig")
  8. group.addoption(
  9. "--setupplan",
  10. "--setup-plan",
  11. action="store_true",
  12. help="show what fixtures and tests would be executed but "
  13. "don't execute anything.",
  14. )
  15. @pytest.hookimpl(tryfirst=True)
  16. def pytest_fixture_setup(fixturedef, request):
  17. # Will return a dummy fixture if the setuponly option is provided.
  18. if request.config.option.setupplan:
  19. fixturedef.cached_result = (None, None, None)
  20. return fixturedef.cached_result
  21. @pytest.hookimpl(tryfirst=True)
  22. def pytest_cmdline_main(config):
  23. if config.option.setupplan:
  24. config.option.setuponly = True
  25. config.option.setupshow = True