conftest.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. @pytest.fixture
  15. def root_xml():
  16. """Root XML element <test>"""
  17. from openpyxl.xml.functions import Element
  18. return Element("test")
  19. ### Markers ###
  20. def pytest_runtest_setup(item):
  21. if isinstance(item, item.Function):
  22. try:
  23. from PIL import Image
  24. except ImportError:
  25. Image = False
  26. if item.get_marker("pil_required") and Image is False:
  27. pytest.skip("PIL must be installed")
  28. elif item.get_marker("pil_not_installed") and Image:
  29. pytest.skip("PIL is installed")
  30. elif item.get_marker("not_py33"):
  31. pytest.skip("Ordering is not a given in Python 3")
  32. elif item.get_marker("lxml_required"):
  33. from openpyxl import LXML
  34. if not LXML:
  35. pytest.skip("LXML is required for some features such as schema validation")
  36. elif item.get_marker("lxml_buffering"):
  37. from lxml.etree import LIBXML_VERSION
  38. if LIBXML_VERSION < (3, 4, 0, 0):
  39. pytest.skip("LXML >= 3.4 is required")