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 8217291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:24:40+00:00 2026-06-07T12:24:40+00:00

I have searched this site top to bottom yet have not found a single

  • 0

I have searched this site top to bottom yet have not found a single way to actually accomplish what I want in Python3x. This is a simple toy app so I figured I could write some simple test cases in asserts and call it a day. It does generate reports and such so I would like to make sure my code doesn’t do anything wonky upon changes.

My current directory structure is: (only relevant parts included)

project
  -model
     __init__.py
     my_file.py
     -test
       my_file_test.py

I am having a hell of a time getting my_file_test.py to import my_file.py.

Like I’ve said. I’ve searched this site top to bottom and no solution has worked. My version of Python is 3.2.3 running on Fedora 17.

Previously tried attempts:
https://stackoverflow.com/questions/5078590/dynamic-imports-relative-imports-in-python-3
Importing modules from parent folder
Can anyone explain python's relative imports?
How to accomplish relative import in python

In virtually every attempt I get an error to the effect of:

ImportError: No module named *
OR
ValueError: Attempted relative import in non-package

What is going on here. I have tried every accepted answer on SO as well as all over the interwebs. Not doing anything that fancy here but as a .NET/Java/Ruby programmer this is proving to be the absolute definition of intuitiveness.

EDIT: If it matters I tried loading the class that I am trying to import in the REPL and I get the following:

>>> import datafileclass
>>> datafileclass.methods
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
>>> x = datafileclass('sample_data/sample_input.csv')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable

If it matters…I know the functionality in the class works but I can’t import it which in the now is causing an inability to test. In the future will certainly cause integration issues. (names changed to protect the innocent)
getting within a couple of weeks of desired functionality for this iteration of the library…any help could be useful. Would have done it in Ruby but the client wants the Python as a learning experience,

  • 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-07T12:24:42+00:00Added an answer on June 7, 2026 at 12:24 pm

    Structure your code like this:

    project
      -model
        __init__.py
        my_file.py
      -tests
        __init__.py
        test_my_file.py
    

    Importantly, your tests directory should also be a module directory (have an empty __init__.py file in it).

    Then in test_my_file.py use from model import my_file, and from the top directory run python -m tests.test_my_file. This is invoking test_my_file as a module, which results in Python setting up its import path to include your top level.

    Even better, you can use pytest or nose, and running py.test will pick up the tests automatically.

    I realise this doesn’t answer your question, but it’s going to be a lot easier for you to work with Python standard practices rather than against them. That means structuring your project with tests in their own top-level directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I have searched this site and found many tutorials on how to
I have searched this site for an answer and found many responses to unsigned/signed
I have searched this site looking for the answer and found similar things, but
I have searched and found a couple of solutions on this site, that didn't
I have searched the site for information and found this: ASP.NET C# Active Directory
I have searched this site and Google and even though the idea is pretty
Preface: I am sure this is incredibly simple, but I have searched this site
I have searched for this, and i found that for api less than 12,
So I have searched for this but not finding anything about it and if
I have searched google, but I didn't find anything. I searched this site and

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.