conftest.py 1.3 KB

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