Skip to main content

Customize test generation with recipies

We are quite often using the functionality to generate tests and it works fine for the most part. It is however often defaulting to use Pythons Unittests, while we prefer to use and have a set up for Pytest.

This typically results in me generating the tests and then ask Sourcery to regenerate all tests for pytest or use some other testing library. It would be awesome if it was possible to provide some kind of context per default when generating tests, such as: “Write tests using pytest, use pytest-mock“ for mocking.”

I mentioned this in a support chat, and you seemed eager to look into it. I figured I can mention it here as well.

Thanks for a great product!

Status: Completed4 comments

Log in to comment and vote

Comments4

  • Nick Thapen

    •

    Jan 24, 2025

    Thanks! I’ve now implemented this and it will be in the release next week.

    It can be saved in the user-level or project level yaml configuration file. There is a UI in the coding assistant which saves to the user-level file - you have to manually edit the project one if you want to override there.

    • Robert Nyström

      •

      Jan 24, 2025

      Cool, thanks a lot. I will try it out as soon as it's available. 😁

  • Robert

    •

    Jan 23, 2025

    Not sure if I follow what you mean with UX. I imagined something added in the .sourcery.yaml like a key called {“context”: {“test“: “HERE IS A DOCSTRING“}}. Not really sure if this is a good way to do it. It is typically a prompt with at least a couple of sentences and might be messy to store like this.

    Maybe possible to add it as part of the configuration in the web app, similar to how the review settings are changed. Not sure how efficient that would be though.

    I would say that this would be per repo, as some repos might use different test setups. For teams would also be nice, as it would then be easier for a whole team to follow the same structure.

  • Nick Thapen

    •

    Jan 21, 2025

    That’s a great idea - what sort of UX do you think would be best here for adding this kind of context?

    Also where would this type of configuration ideally be stored for you (in repo, team level, individual machine, etc)