Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Unit Tests
#1
Hi There! When unittest'ing a simple program that prompts for a first and last name, I'm getting a "repl process died unexpectedly" return.

def get_formatted_name (first, last):
    """Generate a neatly formatted full name."""
    full_name = first + ' ' + last
    return full_name.title()

from main import get_formatted_name

print("Enter 'q' at any time to quit.")
while True:
    first = input("\nPlease give me your first name: ")
    if first == 'q':
        break
    last = input("Please give me your last name: ")
    if last == 'q':
        break
    formatted_name = get_formatted_name(first, last)
    print(f"\tNeatly formatted name: " + formatted_name + '.')

import unittest
from main import get_formatted_name

class NamesTestCase(unittest.TestCase):
    """Tests for 'main.py'."""

    def test_first_last_name(self):
        """Do names like 'Janis Joplin' work?"""
        formatted_name = get_formatted_name('janis', 'joplin')
        self.assertEqual(formatted_name, 'Janis Joplin')

unittest.main()
Error:
---------------------------------------------------------------------- Ran 0 tests in 0.000s OK repl process died unexpectedly: 
Reply
#2
It's working for me:

Output:
. ---------------------------------------------------------------------- Ran 1 test in 0.016s OK
I'm running it from the command line, how are you running it?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Yeah, was running this in Repl.it. I decided to duplicate it in Geany on my RPi and it works fine.

Must be something specific to running tests on Repl.it.
Reply
#4
Good. You have a function that's unit tested, but what about the rest of your program? You have logic in that main loop that isn't tested. Do you have ideas about how you'd test the application as a whole (one might call such a test an end-to-end or functional test)?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Homework Python unit test Paragoon2 4 1,528 Dec-12-2022, 12:45 PM
Last Post: Paragoon2
  Unit 18 Procedural Programming Python kanwal121 4 3,970 Dec-21-2017, 10:53 PM
Last Post: Terafy
  unit 18 codes Miss_Kaur 7 5,034 Dec-19-2017, 02:49 PM
Last Post: sparkz_alot
  Unit 18 Procedural Programming Python kanwal121 6 4,092 Dec-17-2017, 07:18 PM
Last Post: Terafy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020