conftest.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import pytest
  2. # Global objects under tests
  3. @pytest.fixture
  4. def Workbook():
  5. """Workbook Class"""
  6. from openpyxl import Workbook
  7. return Workbook
  8. @pytest.fixture
  9. def Worksheet():
  10. """Worksheet Class"""
  11. from openpyxl.worksheet import Worksheet
  12. return Worksheet
  13. # Global fixtures
  14. ### Markers ###
  15. def pytest_runtest_setup(item):
  16. if isinstance(item, item.Function):
  17. try:
  18. from PIL import Image
  19. except ImportError:
  20. Image = False
  21. if item.get_marker("pil_required") and Image is False:
  22. pytest.skip("PIL must be installed")
  23. elif item.get_marker("pil_not_installed") and Image:
  24. pytest.skip("PIL is installed")
  25. elif item.get_marker("not_py33"):
  26. pytest.skip("Ordering is not a given in Python 3")
  27. elif item.get_marker("lxml_required"):
  28. from openpyxl import LXML
  29. if not LXML:
  30. pytest.skip("LXML is required for some features such as schema validation")
  31. elif item.get_marker("lxml_buffering"):
  32. from lxml.etree import LIBXML_VERSION
  33. if LIBXML_VERSION < (3, 4, 0, 0):
  34. pytest.skip("LXML >= 3.4 is required")
  35. elif item.get_marker("no_lxml"):
  36. from openpyxl import LXML
  37. if LXML:
  38. pytest.skip("LXML has a different interface")
  39. elif item.get_marker("numpy_required"):
  40. from openpyxl import NUMPY
  41. if not NUMPY:
  42. pytest.skip("Numpy must be installed")
  43. elif item.get_marker("pandas_required"):
  44. from openpyxl import PANDAS
  45. if not PANDAS:
  46. pytest.skip("Pandas must be installed")