conftest.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (c) 2010-2019 openpyxl
  2. import pytest
  3. import platform
  4. ### Markers ###
  5. def pytest_runtest_setup(item):
  6. if isinstance(item, pytest.Function):
  7. try:
  8. from PIL import Image
  9. except ImportError:
  10. Image = False
  11. if item.get_closest_marker("pil_required") and Image is False:
  12. pytest.skip("PIL must be installed")
  13. elif item.get_closest_marker("pil_not_installed") and Image:
  14. pytest.skip("PIL is installed")
  15. elif item.get_closest_marker("not_py33"):
  16. pytest.skip("Ordering is not a given in Python 3")
  17. elif item.get_closest_marker("defusedxml_required"):
  18. from openpyxl import DEFUSEDXML
  19. if not DEFUSEDXML:
  20. pytest.skip("defusedxml is required to guard against these vulnerabilities")
  21. elif item.get_closest_marker("lxml_required"):
  22. from openpyxl import LXML
  23. if not LXML:
  24. pytest.skip("LXML is required for some features such as schema validation")
  25. elif item.get_closest_marker("lxml_buffering"):
  26. from lxml.etree import LIBXML_VERSION
  27. if LIBXML_VERSION < (3, 4, 0, 0):
  28. pytest.skip("LXML >= 3.4 is required")
  29. elif item.get_closest_marker("no_lxml"):
  30. from openpyxl import LXML
  31. if LXML:
  32. pytest.skip("LXML has a different interface")
  33. elif item.get_closest_marker("numpy_required"):
  34. from openpyxl import NUMPY
  35. if not NUMPY:
  36. pytest.skip("Numpy must be installed")
  37. elif item.get_closest_marker("pandas_required"):
  38. from openpyxl import PANDAS
  39. if not PANDAS:
  40. pytest.skip("Pandas must be installed")
  41. elif item.get_closest_marker("no_pypy"):
  42. if platform.python_implementation() == "PyPy":
  43. pytest.skip("Skipping pypy")