-
Notifications
You must be signed in to change notification settings - Fork 715
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
pytest_generate_tests in tests/conftest.py takes much more time than before #2790
Comments
Before this commit, TestbedInfo object was being created in every generate_param_* method defined in conftest.py. I optimized it to create the TestbedInfo only once. However, before the generate_param_* methods were being called only if we had a 'enum_*" parameter in the fixture/test case. @Junchao-Mellanox - I added your debug code and ran pytest with '--log-level debug --log-cli-level debug' and see that get_tbinfo is taking only ~0.8 secs. What flags are you turning on when you say run with 'debug log level'
Run
|
A fix for this issue (to be compatible with how the behavior was before) where we were creating TestbedInfo only if the test had 'enum_*' parameterized:
@yxieca @wangxin @Junchao-Mellanox - if this fix is acceptable, I will push it out. |
If we are ok with global variable for duts_in_testbed, then a better solution
|
Hi, I verified both of the fix, all works. |
@sanmalho-git where do we stands with this PR? Is something blocking you or we can move on? |
This is a fix for issue sonic-net#2790 - pytest_generate_tests in tests/conftest.py takes much more time than before The reason for the issue was that creating the TestbedInfo takes 1-9 seconds, and was part of pytest_generate_tests. Since pytest_generate_tests is called for all the tests/fixtures, this was adding a long time when trying to execute many tests. For some of the other dut selection fixtures we were also getting variables for the duts from the inventory files - which also takes a long time - adding to the execution delay. To fix is to use create the TestbedInfo and getting the variables from the inventory files for all the DUTS only once - by storing it in global variables. If these global variables are not set, then we would set them. Thus, creating TestbedInfo and getting variables only once per pytest run
…xtures (#2811) What is the motivation for this PR? pytest_generate_tests dynamically adds enum_* fixtures that select DUTs on which the tests are to be parameterized. In order to select the DUTs on which the tests are to run, we need to get the TestbedInfo and also all variables defined in the inventory file for each DUT. These operations are time consuming - like creating TestbedInfo taking 1-9 seconds, and getting variables from inventory taking 3-5 seconds. pytest_generate_tests is called for all the tests/fixtures that needs to run in a pytest session. This was adding a long time when trying to execute many tests. This issue was reported in issue #2790 - pytest_generate_tests in tests/conftest.py takes much more time than before How did you do it? To fix this, we need to create the TestbedInfo only once, store it, and then use the stored value in the next execution of pytest_generate_tests, rather than re-creating TestbedInfo. Similary, the variables for all the DUTs in the testbed should be read once from the inventory files, stored, and the re-used in the next execution of pytest_generate_tests. PR #2789 Added caching capability to store any facts using pickle. PR #2856 added caching capability for TestbedInfo PR #2873 added caching capability for variables for DUTs in the inventory files. We use the cached TestbedInfo and DUT variables in the selection of DUTs in pytest_generate_tests. How did you verify/test it? Ran tests that use the dut selection fixtures and validated that the delay is seen only once, and not in every call to pytest_generate_tests. Validated the execution time reduced significantly when using caching when executing iface_namingmode test cases which have ~30 tests.
Description
This issue is introduced by commit 077f148. In this commit, it introduced some new lines in function pytest_generate_tests:
It tries to get testbed info here. However, get testbed info takes many time. I added some debug log.
The debug code:
The logs:
As the log shows, get testbed info takes 9 seconds for each call, and the rest of the function only takes no more than 1 ms. Since this function is called many times before the real test, it introduces a 3 minutes delay for each test cases. We don't have to get the testbed info again and again. We need optimize this.
Steps to reproduce the issue:
Describe the results you received:
pytest_generate_tests takes 3 minutes
Describe the results you expected:
pytest_generate_tests should take no more than 15 seconds
Additional information you deem important:
The text was updated successfully, but these errors were encountered: