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

Consider migrating from unittest to pytest #1183

Open
onefloid opened this issue Oct 22, 2024 · 3 comments
Open

Consider migrating from unittest to pytest #1183

onefloid opened this issue Oct 22, 2024 · 3 comments
Milestone

Comments

@onefloid
Copy link
Contributor

Has there been any consideration to migrate from the Python unittest module to pytest? pytest offers several advantages, such as:

  • More concise and readable test code.
  • Less boilerplate and less duplicated code, e.g. with test parametrization
  • More flexible setup and teardown capabilities with fixtures.
  • Broader plugin ecosystem for additional functionality.

I read the tests for ChoreService and believe they could greatly benefit from pytest’s more flexible setup and teardown capabilities. This could lead to cleaner and more maintainable test code. Has this transition been explored or considered? Would love to discuss!

@MariusWirtz
Copy link
Collaborator

I agree we should migrate.

The tests themselves are a large code base though. If we don't migrate all the tests we could end up in situation where we use two testing frameworks.
If we do it we should try to do it in a separate branch or in a kind of all-at-once approach I think.

@onefloid
Copy link
Contributor Author

onefloid commented Oct 24, 2024

I'm happy to hear that you support this change. Yes, I can see the risk of having two test frameworks as well. Especially if the migration takes a long time or gets stuck.

But the downside of having an extra branch where all migrated tests are collected before being merged into master is that this could lead to a lot of duplicate work. If tests are changed or added in master, the already migrated tests would also have to be changed.

The test runner of pytest, which we already use to run the tests, allows us to run tests from both test frameworks: unittest and pytest. So a migration strategy could be to migrate test class by test class. To make sure we are committed to migrate, we could migrate about 30% of the tests before merging them to master the first time. Maybe including the level boss CellService_Test.

We could track the process in an issue and try to motivate other developers to migrate individual test classes.

Happy to hear your thoughts.

@MariusWirtz
Copy link
Collaborator

Yeah. I hear you.
I think we can go ahead with this.

Do you maybe want to refactor one of the smaller test collections, like the ChoreService tests, first?
Then, we could use that as a "beacon" to guide us for the rest of the tests.

@MariusWirtz MariusWirtz added this to the 2.1 milestone Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants