Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8552081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:20:31+00:00 2026-06-11T14:20:31+00:00

I’m following this tutorial on web2py where you get to make a testdriven environment.

  • 0

I’m following this tutorial on web2py where you get to make a testdriven environment. However when I try to run the test with unittest, selenium I get this error:

$ python functional_tests.py
running tests
Traceback (most recent call last):
  File "functional_tests.py", line 56, in <module>
    run_functional_tests()
  File "functional_tests.py", line 46, in run_functional_tests
    tests = unittest.defaultTestLoader.discover('fts')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 202, in discover
    raise ImportError('Start directory is not importable: %r' % start_dir)
ImportError: Start directory is not importable: 'fts'

This is how the functional_tests.py looks like:

#!/usr/bin/env python
try: import unittest2 as unittest #for Python <= 2.6
except: import unittest
import sys, urllib2
sys.path.append('./fts/lib')
from selenium import webdriver
import subprocess
import sys
import os.path

ROOT = 'http://localhost:8001'

class FunctionalTest(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.web2py = start_web2py_server()
        self.browser = webdriver.Firefox()
        self.browser.implicitly_wait(1)

    @classmethod    
    def tearDownClass(self):
        self.browser.close()
        self.web2py.kill()

    def get_response_code(self, url):
        """Returns the response code of the given url

        url     the url to check for 
        return  the response code of the given url
        """
        handler = urllib2.urlopen(url)
        return handler.getcode()


def start_web2py_server():
    #noreload ensures single process
    print os.path.curdir    
    return subprocess.Popen([
            'python', '../../web2py.py', 'runserver', '-a "passwd"', '-p 8001'
    ])

def run_functional_tests(pattern=None):
    print 'running tests'
    if pattern is None:
        tests = unittest.defaultTestLoader.discover('fts')
    else:
        pattern_with_globs = '*%s*' % (pattern,)
        tests = unittest.defaultTestLoader.discover('fts', pattern=pattern_with_globs)

    runner = unittest.TextTestRunner()
    runner.run(tests)

if __name__ == '__main__':
    if len(sys.argv) == 1:
        run_functional_tests()
    else:
        run_functional_tests(pattern=sys.argv[1])
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:20:33+00:00Added an answer on June 11, 2026 at 2:20 pm

    I had the same problem and based on an excellent article unit testing with web2py,
    I got this to work by doing the following:

    1. Create a tests folder in the tukker directory
    2. Copy/save the amended code(below) into tests folder as alt_functional_tests.py
    3. Alter the web2py path in the start_web2py_server function to your own path
    4. To run, enter the command: python web2py.py -S tukker -M -R applications/tukker/tests/alt_functional_tests.py

    I am no expert but hopefully this will work for you also.


    import unittest
    
    from selenium import webdriver
    
    import subprocess
    
    import urllib2
    
    
    execfile("applications/tukker/controllers/default.py", globals())
    
    ROOT = 'http://localhost:8001'
    
    def start_web2py_server():
        return subprocess.Popen([
            'python', '/home/alan/web2py/web2py/web2py.py', 'runserver',
             '-a "passwd"', '-p 8001' ])
    
    class FunctionalTest(unittest.TestCase):
    
        @classmethod
        def setUpClass(self):
            self.web2py = start_web2py_server()
            self.browser = webdriver.Firefox()
            self.browser.implicitly_wait(1)
    
        @classmethod    
        def tearDownClass(self):
            self.browser.close()
            self.web2py.kill()
    
        def get_response_code(self, url):
            """Returns the response code of the given url
            url     the url to check for 
            return  the response code of the given url
            """
            handler = urllib2.urlopen(url)
            return handler.getcode()
    
        def test_can_view_home_page(self):
            # John opens his browser and goes to the home-page of the tukker app
            self.browser.get(ROOT + '/tukker/')
            # He's looking at homepage and sees Heading "Messages With 300 Chars"
            body = self.browser.find_element_by_tag_name('body')
            self.assertIn('Messages With 300 Chars', body.text)
    
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(FunctionalTest))
    unittest.TextTestRunner(verbosity=2).run(suite)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.