-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set the staged of tests running? #3053
Comments
GitMate.io thinks the contributor most likely able to help you is @robert-cody. |
The fact that one test is implicitly dependent on another is probably not a good idea. You would be better of creating the data files in a fixture, for example, and then all the tests which require the files (including the test that validates them) can request the fixture. But if you really want to control the order of the tests, you can do that using the pytest_collection_modifyitems hook: https://docs.pytest.org/en/latest/writing_plugins.html#_pytest.hookspec.pytest_collection_modifyitems |
@brianmaissy It seems, that controlling the order of the test would be better in my case, bacause I want to test where file is saved. When it is used by script from other working directories the ralatives paths can be other to save files and different scripts which used this files can be not work. Can you give me some example of code that change the order of the tests? And links in docs, that you have used to write this? I don't understand how it must be used in link upper. |
Given the following tests: def test_requires_file():
assert open('temp', 'rb').read() == 'hello'
def test_creates_file():
open('temp', 'wb').write('hello') This hook implementation could move the test which creates the file to the beginning of the list: def pytest_collection_modifyitems(session, config, items):
file_creator_test = [test_function for test_function in items if test_function.name == 'test_creates_file'][0]
items.remove(file_creator_test)
items.insert(0, file_creator_test) Or even better, take a look at the pytest-ordering plugin, which does things like this for you: |
Note you can do all that with a fixture (fixtures can also use |
This can probably be closed |
Thanks @brianmaissy for the ping! 👍 |
Hello! My project has structure like this:
app
-dir1
--module1.py
--mudule2.py
-dir2
--module1.py
-tests
--dir1
---test_module1.py
---test_module2.py
---conftest.py
--dir2
---test_module1.py
---conftest.py
--conftest.py
In test_module1.py I create and test creating important data-files from wich depends all other programm tests. On tests.conftest.py all this data is cleared.
But I am not understand, why when I execute 'pytest tests' run test_module2.py at first. And of course it is fail because data from test_module1.py is not exist on its time. And one more fact, that after that test_module1.py don't run at all.
Say me please, how can I set the steps of running my tests?
The text was updated successfully, but these errors were encountered: