conftest.py 782 B

1234567891011121314151617181920212223242526
  1. import sys
  2. import re
  3. _VERSION_MARKER = re.compile(r'_py(?P<major_version>\d)(?P<minor_version>\d)?')
  4. def pytest_ignore_collect(path, config):
  5. """
  6. Ignore tests that end with _pyX, where X does not equal this
  7. interpreter's major version.
  8. """
  9. filename = path.basename
  10. modulename = filename.split('.', 1)[0]
  11. match = _VERSION_MARKER.search(modulename)
  12. if not match:
  13. return False
  14. major_version = match.group('major_version')
  15. minor_version = match.group('minor_version')
  16. if minor_version:
  17. version_match = (int(major_version), int(minor_version)) == sys.version_info[:2]
  18. else:
  19. version_match = int(major_version) == sys.version_info[0]
  20. return not version_match # because this is an _ignore_ (not an include)