Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python TDD
#1
I am trying to go through Test-Driven Development with Python.
I am currently in section 1 chapter 2.
I have installed Django and selenium.
I have made manage.py
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "superlists.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        try:
            import django
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise
    execute_from_command_line(sys.argv)
and functional_tests.py
from selenium import webdriver
import unittest


class NewVisitorTest(unittest.TestCase):

    def setUp(self):
        self.browser = webdriver.Firefox()


    def tearDown(self):
        self.browser.quit()


    def start_list(self):
        self.browser.get('http://localhost:8000')
        self.assertIn('To-Do', self.browser.title)
        self.fail("Finish the test!")


if __name__ == "__main__":
    unittest.main()
I run manage.py runserver to start the server.
When I run functional_tests.py per the book it doesn't run the tests. Why? Wall
Output:
(virtualenv) PS C:\Users\User\mystuff\TDD_python> python functional_test.py ---------------------------------------------------------------------- Ran 0 tests in 0.000s OK (virtualenv) PS C:\Users\User\mystuff\TDD_python>
Reply
#2
The tests aren't named correctly. Test classes, modules and I believe functions have to be named in a particular way to be discovered. See the docs. Also, why do you need line 18? The test framework will report pass or fail depending on the assertions; you don't need to do anything more usually.
Reply
#3
(Aug-12-2020, 06:31 AM)ndc85430 Wrote: Also, why do you need line 18? The test framework will report pass or fail depending on the assertions; you don't need to do anything more usually.
That is just a place holder in the tutorial.
Thanks for the help.
Reply
#4
Note that I've edited my post to point you to the docs. It has been a while since I've done any serious Python, so I've forgotten what the rules are for test discovery.
Reply


Forum Jump:

User Panel Messages

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