conftest.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """Test configuration"""
  2. import os
  3. import pytest
  4. import _pytest.skipping
  5. from dotenv import load_dotenv
  6. from python_anticaptcha import AnticaptchaClient
  7. from rival_regions_wrapper.middleware import LocalAuthentication
  8. load_dotenv()
  9. class MissingAuthenticationError(Exception):
  10. """Error for missing authentication"""
  11. def pytest_addoption(parser):
  12. """Add option to parser to prevent skips"""
  13. parser.addoption(
  14. "--no-skips",
  15. action="store_true",
  16. default=False, help="disable skip marks")
  17. @pytest.hookimpl(tryfirst=True)
  18. def pytest_cmdline_preparse(config, args):
  19. """Add check for skips"""
  20. if "--no-skips" not in args:
  21. return
  22. def no_skip(*args, **kwargs):
  23. return
  24. _pytest.skipping.skip = no_skip
  25. @pytest.fixture(scope='module')
  26. def vcr(vcr):
  27. """Set parameters vor VCR"""
  28. vcr.ignore_localhost = True
  29. return vcr
  30. @pytest.fixture(scope="module")
  31. def middleware():
  32. """Set up wrapper before test"""
  33. username = os.environ.get('USERNAME', None)
  34. password = os.environ.get('PASSWORD', None)
  35. login_method = os.environ.get('LOGIN_METHOD', None)
  36. captcha_key = os.environ.get('CAPTCHA_KEY', None)
  37. if None in (username, password, login_method):
  38. raise MissingAuthenticationError(
  39. 'Load the following variables in your user environment: '
  40. 'username, password, login_method'
  41. )
  42. _middleware = LocalAuthentication(
  43. False, AnticaptchaClient(captcha_key)
  44. )
  45. return _middleware.set_credentials(
  46. username, password, login_method
  47. )