Pytest Results are different than my results Scientific Computing with Python Projects - Arithmetic Formatter

Greetings,

I am developing my code in my Notepad++ application since i am more used to running code there. Instead of referencing several python files like what is being done in the replit structure i simply call the function with the same arguments in my notepad++ and test to see the results in the end. Every once in a while I copy the code back into replit to see if everything is all right.

However, the results are different. For some reason the Pytest code always gets the " Too many problems" error on every single test. I tried running through the pytest files but I can’t figure out why it gets this error.

I should have a PASSED on all error conditions. I am worried i’m doing something wrong and even if I get all other conditions right I’m still going to keep getting all these wierd PyTest Errors

This is my replit code:
https://replit.com/join/osjqcadoao-lucasbalestrass

This is my base code on Notepad++

def arithmetic_arranger(problems):
  arranged_problems = 1 
# Checks if answers should be shown
  show_answers = False
  if problems[len(problems)-1] == True:
    show_answers = True
  problems = problems[0] 


    # Checks conditions
  # If number of problems > 5
  if len(problems) > 5:
    arranged_problems = "Error: Too many problems."
    return arranged_problems
    print(len(problems))
    
    
  # If operator is not + or -
  for problem in problems:
    if (problem.find("/") > 0):
      arranged_problems = "Error: Operator must be '+' or '-'."   
      return arranged_problems  
  
    # if (problem.find("+") > 0) or (problem.find("-") > 0):
        # continue
    # else:
        # arranged_problems = "Error: Operator must be '+' or '-'."   
        # return arranged_problems
  
  
  
  problem_list = []
  for problem in problems: 
    problem = problem.split(' ')
    problem_list.append(problem)
  psize = 0  
  # print(problem_list)
  for problem in problem_list:
    for p in problem:
        if len(p) > psize:
            psize = len(p)
  if psize > 4:
    arranged_problems = "Error: Numbers cannot be more than four digits."
    return arranged_problems
  
  for problem in problem_list:
    try:
        problem[0] = int(problem[0])
        problem[2] = int(problem[2])
    except:
        arranged_problems = "Error: Numbers must only contain digits."
        return arranged_problems
        
  arranged_problems = []
  return arranged_problems
  
teste = 0

problems = [['3801 - 2', '123 + 49']]
teste = teste + 1
print("Teste: "," ",teste," ",problems) 
print(arithmetic_arranger(problems))

problems = [['1 + 2', '1 - 9380']]
teste = teste + 1
print("Teste: "," ",teste," ",problems) 
print(arithmetic_arranger(problems))

problems = [['3 + 855', '3801 - 2', '45 + 43', '123 + 49']]
teste = teste + 1
print("Teste: "," ",teste," ",problems) 
print(arithmetic_arranger(problems))

problems = [['11 + 4', '3801 - 2999', '1 + 2', '123 + 49', '1 - 9380']]
teste = teste + 1
print("Teste: "," ",teste," ",problems) 
print(arithmetic_arranger(problems))

problems = [['44 + 815', '909 - 2', '45 + 43', '123 + 49','888 + 40', '653 + 87']]
teste = teste + 1
print("Teste: "," ",teste," ",problems) 
print(arithmetic_arranger(problems))

problems = [['3 / 855', '3801 - 2', '45 + 43', '123 + 49']]
teste = teste + 1
print("Teste: "," ",teste," ",problems) 
print(arithmetic_arranger(problems))

problems = [['24 + 85215', '3801 - 2', '45 + 43', '123 + 49']]
teste = teste + 1
print("Teste: "," ",teste," ",problems) 
print(arithmetic_arranger(problems))

problems = [['98 + 3g5', '3801 - 2', '45 + 43', '123 + 49']]
teste = teste + 1
print("Teste: "," ",teste," ",problems) 
print(arithmetic_arranger(problems))

problems = [['3 + 855', '988 + 40'], True]
teste = teste + 1
print("Teste: "," ",teste," ",problems) 
print(arithmetic_arranger(problems))

problems = [['32 - 698', '1 - 3801', '45 + 43', '123 + 49', '988 + 40'], True]
teste = teste + 1
print("Teste: "," ",teste," ",problems) 
print(arithmetic_arranger(problems))

This is not how you set an argument with a default value

Here you are destroying the entire problems list and replacing it with the string for the first problem.

1 Like

Hey @JeremyLT. Thank you very much for your input.

Indeed, i have reviewed google and fixed the default value argument.

def arithmetic_arranger(problems, show_answers = False):

About the second part of your answer. I got confused since the pytest parameters were given in double brackets ([[β€˜3801 - 2’, β€˜123 + 49’]]). I retested the code and now it is working.

test_cases = [
    pytest.param(
        [['3801 - 2', '123 + 49']],
        '  3801      123\n'
        '-    2    +  49\n'
        '------    -----',
        'Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]',

Thank you very much!