Issues with Replit Pytest suite

Tell us what’s happening:
I’m having some issues with the provided unit tests in the Arithmetic Formatter challenge.

When run individually, each test in the default test_module.py works fine. But when run altogether (as the starter code is set up to do), several of them fail. Output from the console shows that some tests are re-using the parameters from previous tests as well, causing an issue with the output.

For example, here is one unit test that should be using the parameters [‘1 + 2’, ‘1 - 9380’], but for some reason inputs from the first unit test are mixed in ([‘3801 - 2’, ‘123 + 49’]):

Would anyone have some insights into why this might be causing so many issues? Again, commenting out the interfering tests means that I can get each to work on their own, which is super odd.

Your project link(s)

solution: https://replit.com/@merigrey/boilerplate-arithmetic-formatter#arithmetic_arranger.py

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36

Challenge: Arithmetic Formatter

Link to the challenge:

Notice where is declared arranged_problems. Using global variables can result in unexpected side effects. This is a case here, function during one of the tests modifies that variable, which is later used by next test, resulting in seemingly having two test cases glued together.

3 Likes

That is super insightful, thank you so much! Your explanation makes sense, I had a gap in my understanding of the global variable, I didn’t even think of that becoming an issue. With a quick fix, I was able to get all tests to pass.

Thank you so much :slight_smile:

2 Likes