r/learnpython • • Oct 21 '26

Need help with building tests and understanding OOP design patterns

I am a post-bacc student currently in a Python for Web API online course. We just wrapped up our calculator application unit, where we learned how to build comprehensive dynamic tests using OOP design patterns. However, I finished the unit a lot more lost than when I started. Building parameterized tests still puzzles me, especially whenever I'm building the majority of a test from scratch rather than fixing minor errors in the code. Even when I do use AI to help me work through my assignments, none of it really sticks. Most of the time, I feel like I'm copying and pasting code whenever mine is incorrect and not really learning.

What are resources that you all would recommend for learning how to build application tests and files with OOP concepts? Any online resources with interactive, hands-on lessons would be greatly appreciated.

4 Upvotes

16 comments sorted by

View all comments

1

u/DimensionMost8342 Oct 21 '26

The mental model that makes parameterized tests less scary: one test function, pytest runs it once per row of data you list.

import pytest

@pytest.mark.parametrize("raw, expected", [("12", 12.0), ("abc", None)]) def test_parse(raw, expected): assert parse_input(raw) == expected

For practice: close the AI, open your calculator, and write three tests for one function from scratch: the normal case, an edge case (divide by zero or empty input), and a bad input. Repeat per function until the pattern sticks. The official pytest tutorial covers parametrize step by step (docs.pytest.org).

1

u/uzuis_4thwife Oct 21 '26

You explained it sm better than my professor did over the course of two 75-minute lectures 😩 he really threw us into the wolves! Thank you so much, I’ll try this when working on my midterm project

1

u/DimensionMost8342 Oct 21 '26

Happy to be of help, goodluck with your project 😊

1

u/jmacey Oct 21 '26

Do you know how decorators work? If not revise this as it will really help understand all the pytest decorators. Anything begining with an @ is a decorator. (Strangly I have been teaching the same thing this week!).

1

u/uzuis_4thwife Oct 21 '26

Reading through these comments, I think my class conflated things a lot more than necessary once we hit the design patterns unit. I realize this is all fairly straightforward info, but I really appreciate all the advice I’ve been receiving 🥹

1

u/DimensionMost8342 Oct 21 '26

Fair, that's cleaner than how I put it. Honestly that @ line covers most of it: once you see @decorator as "call this function with the thing underneath and use what comes back," @fixture and @parametrize aren't separate things to memorize anymore. I kept it out of the OP mainly because I didn't want to scare off anyone who hadn't hit @ yet, but I'm stealing it.