conftest.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. import os
  5. import pytest
  6. from mozlint import LintRoller
  7. here = os.path.abspath(os.path.dirname(__file__))
  8. @pytest.fixture
  9. def lint(request):
  10. lintargs = getattr(request.module, 'lintargs', {})
  11. return LintRoller(root=here, **lintargs)
  12. @pytest.fixture(scope='session')
  13. def filedir():
  14. return os.path.join(here, 'files')
  15. @pytest.fixture(scope='module')
  16. def files(filedir, request):
  17. suffix_filter = getattr(request.module, 'files', [''])
  18. return [os.path.join(filedir, p) for p in os.listdir(filedir)
  19. if any(p.endswith(suffix) for suffix in suffix_filter)]
  20. @pytest.fixture(scope='session')
  21. def lintdir():
  22. return os.path.join(here, 'linters')
  23. @pytest.fixture(scope='module')
  24. def linters(lintdir, request):
  25. suffix_filter = getattr(request.module, 'linters', ['.lint'])
  26. return [os.path.join(lintdir, p) for p in os.listdir(lintdir)
  27. if any(p.endswith(suffix) for suffix in suffix_filter)]