You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Super sorry for asking something that's probably been beaten to death, but I have a question regarding this and it's been hard to find comprehensive info about this online. Can't hurt to ask, eh?
Scenario: I have a suite of Selenium tests using pytest. The tests also have read access to a DB to pull reliable information (instead of hard coding values) for testing scenarios. e.g. I have a test user and use queries to pull back their user id, and some item ids (which sometimes change) in preparation for certain tests.
I have my tests set up using test classes that are marked using pytest mark, for organization and a conftest with a class scoped fixture used for instantiating the webdriver for each test class.
Inside my test classes is where my concern is. I would like to make any DB calls only once and cache the values for the duration of the TestClass being run, but still need each instance to have access to the data. I have accomplished this by utilizing another class scoped fixture per class:
@pytest.fixture(scope="class")deftestClassSetup(request):
BaseTest.__init__(request.cls, request.cls.driver)
request.cls.log.info("Running class setup")
request.cls.page_model=PageModel(request.cls.driver)
# DATA STUFFrequest.cls.company=request.cls.companyData.getTestCompanyAndAccountId(TEST_COMPANY)
request.cls.items=request.cls.itemData.getTestItemsByAccountId(request.cls.company['AccountId'], 5)
@pytest.mark.cooltest@pytest.mark.usefixtures("classDriverSetup", "testClassSetup")classTestClass(unittest.TestCase, BaseTest):
This works, but it seems maybe a little too heavy handed. Is there a better way to go about this?
pause for effect
The real reason I don't like this is...ehem....it totally wrecks intellisense in pycharm for me and it makes writing out tests more of a pain, haha. What do you think, should I just say screw it and use the typical autouse-fixture-inside-the-class-technique and just allow all the db calls?
...(I could probably come up with another caching mechanism outside my test classes as well.... 🤔)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Super sorry for asking something that's probably been beaten to death, but I have a question regarding this and it's been hard to find comprehensive info about this online. Can't hurt to ask, eh?
Scenario: I have a suite of Selenium tests using pytest. The tests also have read access to a DB to pull reliable information (instead of hard coding values) for testing scenarios. e.g. I have a test user and use queries to pull back their user id, and some item ids (which sometimes change) in preparation for certain tests.
I have my tests set up using test classes that are marked using pytest mark, for organization and a conftest with a class scoped fixture used for instantiating the webdriver for each test class.
Inside my test classes is where my concern is. I would like to make any DB calls only once and cache the values for the duration of the TestClass being run, but still need each instance to have access to the data. I have accomplished this by utilizing another class scoped fixture per class:
and here's my conftest fixture (for clarity):
This works, but it seems maybe a little too heavy handed. Is there a better way to go about this?
pause for effect
The real reason I don't like this is...ehem....it totally wrecks intellisense in pycharm for me and it makes writing out tests more of a pain, haha. What do you think, should I just say screw it and use the typical autouse-fixture-inside-the-class-technique and just allow all the db calls?
...(I could probably come up with another caching mechanism outside my test classes as well.... 🤔)
Beta Was this translation helpful? Give feedback.
All reactions