-
Notifications
You must be signed in to change notification settings - Fork 203
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
Draft: Migrate test_cgroups.py and test_benchmark_definiton.py to pytest framework #908
Conversation
In this modified code, I have created a new fixture called The fixture also adds a finalizer function that disables logging after the test has completed, ensuring that logging is only enabled for the duration of the test. To use this fixture, we simply add it as an argument to each test function that requires logging. When pytest runs the test, it will automatically call the fixture function and pass it as an argument to the test function. This will allow us to enable logging for specific tests without cluttering the output of other tests. |
How does this look for the developer? How will they see the log?
Is there a way to achieve this without having to add it to every single test manually?
Actually, this is not my main concern. If we have a decent handling of log output for tests, we can just use it for all tests and do not need to worry about fiddling with log levels at all. Only if we do not have a decent handling of log outputs for tests and need to disable logging, then we need to make sure it is actually disabled for each test. |
There are multiple ways a developer can do this
Yes! We can achieve this task by defining a custom Pytest plugin. These plugins will allow us to extend Pytest's functionality by defining custom hooks that are called at various points during the test running process. We can define a custom plugin that sets up logging configuration for specific tests based on configuration options or markers, and then use the |
How would that caplog solution look like? Can you show a concrete example? Or tell me how to try it out? |
So, I tried adding the caplog solution to our test and used We can use these command to read the caplog text file: When we run our tests with this command, pytest will capture all log messages and save them to the specified file. We can then open the file in a text editor to read the log messages. |
So, I have now invested some time into playing around with this and reading the tutorial, and found the following:
So in summary, pytest is really nice in this regard, we can and want to get rid of all manual logging configs in tests, and we might want to set some nice logging format for pytest in |
Hi! sorry for being inactive, my current semester is ending soon so I'm busy with project submissions and other stuff! will work on this as soon as I get time. |
Hi @PhilippWendler, I was wondering which format should we use and should we implement the caplog solution or not? |
I see no benefit in |
Made the required changes and migrated test_benchmark_definition.py too |
Looks fine! |
Hi @PhilippWendler! I was wondering if I should open a new PR for next workloads or add more commits to this PR? (P.S. Currently working on the next files to migrate) |
I think it makes sense to see this as a prototype, and create a fresh PR for the actual changes. We don't need the commits for trying out. And of course, we need the changes to the tests in the original files and not in additional new files. |
Will be superseded by other PRs. |
I have successfully created a small prototype for
test_cgroups.py
which works for pytest. The test was running successfully on my Linux machine.