Python TDD - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python TDD (/thread-28968.html) |
Python TDD - mcmxl22 - Aug-12-2020 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?
RE: Python TDD - ndc85430 - Aug-12-2020 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. RE: Python TDD - mcmxl22 - Aug-12-2020 (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. RE: Python TDD - ndc85430 - Aug-12-2020 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. |