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

  • SEARCH
  • Home
  • 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 6586179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:45:28+00:00 2026-05-25T16:45:28+00:00

I am sure this is simple to solve, but I have been staring at

  • 0

I am sure this is simple to solve, but I have been staring at it for so long that I am staring straight past the solution. Any tips/hints/suggestions/solutions appreciated!

I am trying to add some unittests to my app engine app. I am using the testrunner.py example from http://code.google.com/appengine/docs/python/tools/localunittesting.html (bottom of the page). This works fine if I put the unittest file (named ‘test_lib.py’) in the root of the app (myapp), however I want to move the tests to a separate subdirectory (named ‘tests’) within the app. Now I need to import some of the modules from the app, however since the working directory of the unittest file is now one level deeper, it does not sees the actual modules from my app engine app.

I tried adding a __ init__.py to the tests and added the following code to the it:

    import os
    import sys

    sys.path.append(os.path.dirname(os.getcwd()))

I hoped this would find the current working directory and go one level up and add this to the sys.path and from that I would be able to import ‘util.lib’ in the unittest file (‘test_lib.py’). However when I run the testrunner.py I still get error “ImportError: No module named util.lib” -> I am trying here to import a module called lib within a subdirectory called util within the root ‘myapp’. My directory structure is as follows:

    testrunner.py
    |- myapp
            |- __init__.py
            |- util
                    |- __init__.py
                    |- lib.py
            |- tests
                    |- __init__.py  ## this file has the import mentioned above.
                    |- test_lib.py

I also tried adding the import of the root of the app to the testrunner but this returns the same error.

    def main(sdk_path, test_path):
        sys.path.append(os.path.dirname(test_path))  ## This line I added to the testrunner.
        sys.path.insert(0, sdk_path)
        import dev_appserver
        dev_appserver.fix_sys_path()
        suite = unittest2.loader.TestLoader().discover(test_path)
        unittest2.TextTestRunner(verbosity=2).run(suite)

And I am calling the test with the following command:

    ./testrunner.py ~/sdk/google_appengine/ myapp/tests/

Any suggestions what I am missing here?

  • 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-05-25T16:45:28+00:00Added an answer on May 25, 2026 at 4:45 pm

    Have you tried to use an absolute path?

    sys.path.append(os.path.abspath(os.path.dirname(test_path)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sure this is something simple but I've been staring at it for a
Im sure this is simple but newbie here. I have 5 URLS cards.php&type=one cards.php&type=two
I have been trying to solve this for the past 2 days with no
I'm sure that it's due to a silly mistake, but I have been debuging
I'm sure this is simple but I can't figure out how to achieve it:
Sorry, I'm sure this is simple but I'm tired and can't figure it out.
Im sure this is pretty simple but I just cant seem to find the
Im pretty sure this has a simple solution. I am using jCarousellite, and i
I'm sure this is really simple, but I can't for the life of me
I'm sure this is really simple and I'm drawing a giant blank, but how

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.