There is a code:

import unittest ... class TestCase_05_SomeTest(unittest.TestCase): @classmethod def setUpClass(cls): login_function(login=LOGIN, password=PASSWORD) ... if __name__ == "__main__": unittest.main() 

How can I run TestCase_05_SomeTest with different logins / passwords and where should I store them? Naturally, I have more than one test case and more than one step. There is no need to merge into TestSuite yet (although the proposal for solving this problem is also accepted).

  • In our php backwater this is solved through dataProviders, and here is the implementation on python . - etki
  • Hmm, amusing, but in my case it will not be possible to hang the decorator on the setUpClass function, it will be meaningless, since if it is done, it will be run several times before running all the tests of this test case, and the tests will be performed only with the last specified login / password, I suspect. - _Aleksandr_19
  • one
    @ _Aleksandr_, if setUpClass is a method for preparing a class for testing, then no login_function should be called exactly there. This is the job of preparing a function for a specific test that is "sponsored" by the data provider, or even the test itself. As far as I understand, you are generally trying to implement an integration / acceptance testing script, and there is no place for it at all in unit tests. - etki
  • those. do you propose to login in each test? in my opinion not the most elegant solution, considering that I have> 50 tests ... there must be another solution, I think so - _Alexander_
  • @ _Aleksandr_, what’s so ineffective here is cramming functional or integration tests into modular ones. Unit tests are designed for isolated testing of individual sections of code, and before each test it is recommended to perform actions that ensure environment zeroing. In general, I am silent, that these are tests, and there should be no concern for resources. - etki

1 answer 1

Hello!

And if you put logins / passwords into a separate configuration file as an array and call them from there?

For example, if it is necessary to use users with certain properties (privileges, types, etc.), then specify them as a key parameter.

And if you need to call to check on all users, then call as a loop through the array of logins.

It all depends on the conditions.

  • one
    It's all obvious, I'm interested in a specific implementation. - _Aleksandr_19