conftest.py 964 B

12345678910111213141516171819202122232425262728293031323334
  1. import yaml
  2. import pytest
  3. from twhatter.parser import TweetBase, User
  4. @pytest.fixture(scope="session")
  5. def fixtures_factory():
  6. """Factory for any kind of data that can be stored in YAML format"""
  7. def _fixtures_factory(yaml_file):
  8. with open(yaml_file, 'r') as f:
  9. fixtures = yaml.load(f)
  10. return fixtures
  11. return _fixtures_factory
  12. @pytest.fixture(scope="session")
  13. def tweets_factory(fixtures_factory):
  14. """Factory for tweets from YAML file"""
  15. def _tweets_factory(yaml_file):
  16. all_fixtures = fixtures_factory(yaml_file)
  17. return [t for t in all_fixtures if isinstance(t, TweetBase)]
  18. return _tweets_factory
  19. @pytest.fixture(scope="session")
  20. def users_factory(fixtures_factory):
  21. """Factory for tweets from YAML file"""
  22. def _users_factory(yaml_file):
  23. all_fixtures = fixtures_factory(yaml_file)
  24. return [u for u in all_fixtures if isinstance(u, User)]
  25. return _users_factory