Skip to content
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: Add a Pytest-based Testsuite #1037

Closed
wants to merge 5 commits into from

Conversation

schroeding
Copy link
Contributor

@schroeding schroeding commented May 6, 2024

This branch introduces a second testsuite, using pytest, in addition to the existing nose-based testsuite. The goal is to migrate the current testsuite to pytest, making it obsolete (see Issue 162).

Note that, if we want to use pytest features like test function parameterization (i.e. using a pytest decorator instead of having helper methods, which call another test method multiple times with different parameters),
the new testsuite will have a larger number of tests - nose sees e.g. a helper method which calls the actual test with 4 different parameter combinations and assert statements as a single test, pytest will report it as 4 tests.

Short feedback if we want to use pytest parameterization or just translate the current tests as they are with as few changes as possible would be appreciated. For an example how the tests would be rewritten, see e.g. commit dad90346f320a2447b2dd1d91a15c3a3e3342a18.

Upside would be that any failing call to a test method, which currently is hidden inside helper methods, would be directly reported by pytest without having to check manually which assertion failed, i.e. tests would be finer. Would also clearly separate the test data from the actual tests. Downside would be the need to rewrite significant parts of the testsuite and that there wouldn't be a 1:1 relation between the current and new testsuite, but a 1:n relation.

schroeding added 5 commits May 6, 2024 14:36
Adds a dependency for pytest and configurates it to search for files following the pytest_* scheme.

After the transition to pytest is completed and the nose-based testsuite can be safely removed, it is probably a good idea to rename the pytest-based testsuite back to the current test_* scheme.

While having both testsuites at the same time causes temporary code duplication, it makes the transition process easier and allows quick three-way diffs between the main branch and the, on this branch, unmodified tests (via git diff) and the changes specific to pytest (via regular diff on this branch).
The current structure with test methods, which are called by other methods with certain values, is not required for simple test methods with static parameters  when using pytest - we can just use test parametrization.

**Note**: This will, as a side-effect, increase the number of tests significantly, as every single call of a method with certain parameters will be reported as its own "test", but will allow a direct report which parameter failed by pytest, instead of having to look in the test log for the failed assert statement - and it should reduce the complexity a bit.
@schroeding schroeding self-assigned this May 6, 2024
@PhilippWendler
Copy link
Member

Short feedback if we want to use pytest parameterization or just translate the current tests as they are with as few changes as possible would be appreciated.

Your discussion of this question is fully correct. If parameterized tests are now easy, we would like to have their advantages.

I would, however, tend to say this should be a two-step process: First migrate to pytest with the existing pattern of tests, and afterwards improve the tests to be parameterized. This would have the advantage of making the first step less complex and make it easier to compare the number of tests during the migration and to review the changes.

@PhilippWendler
Copy link
Member

Can you please use a branch in this repository and not a fork? Only this way you get CI that executes the tests.

@schroeding schroeding closed this May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants