Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49449 > unrolled thread
| Started by | Martin Schöön <martin.schoon@gmail.com> |
|---|---|
| First post | 2013-06-29 19:13 +0000 |
| Last post | 2013-06-29 21:19 +0000 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
Unittest fails to import module Martin Schöön <martin.schoon@gmail.com> - 2013-06-29 19:13 +0000
Re: Unittest fails to import module Roy Smith <roy@panix.com> - 2013-06-29 15:25 -0400
Re: Unittest fails to import module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-29 19:26 +0000
Re: Unittest fails to import module Martin Schöön <martin.schoon@gmail.com> - 2013-06-29 21:19 +0000
| From | Martin Schöön <martin.schoon@gmail.com> |
|---|---|
| Date | 2013-06-29 19:13 +0000 |
| Subject | Unittest fails to import module |
| Message-ID | <b38pvbFjlv9U1@mid.individual.net> |
I know the answer to this must be trivial but I am stuck... I am starting on a not too complex Python project. Right now the project file structure contains three subdirectories and two files with Python code: code blablabla.py test blablabla_test.py doc (empty for now) blablabla_test.py contains "import unittest" and "import blablabla" $PYTHONPATH points at both the code and the test directories. When I run blablabla_test.py it fails to import blablabla.py I have messed around for oven an hour and get nowhere. I have done unittesting like this with success in the past and I have revisited one of those projects and it still works there. The older project has a slightly flatter structure as it lacks a separate code subdirectory: something.py test something_test.py I have temporarily tried this on the new project but to no avail. Any leads? TIA /Martin
[toc] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2013-06-29 15:25 -0400 |
| Message-ID | <roy-6352F8.15251029062013@70-1-84-166.pools.spcsdns.net> |
| In reply to | #49449 |
In article <b38pvbFjlv9U1@mid.individual.net>, Martin Schöön <martin.schoon@gmail.com> wrote: > I know the answer to this must be trivial but I am stuck... > > I am starting on a not too complex Python project. Right now the > project file structure contains three subdirectories and two > files with Python code: > > code > blablabla.py > test > blablabla_test.py > doc > (empty for now) > > blablabla_test.py contains "import unittest" and "import blablabla" > > $PYTHONPATH points at both the code and the test directories. A couple of generic debugging suggestions. First, are you SURE the path is set to what you think? In your unit test, do: import sys print sys.path and make sure it's what you expect it to be. > When I run blablabla_test.py it fails to import blablabla.py Get unittest out of the picture. Run an interactive python and type "import blablabla" at it. What happens? One trick I like is to strace (aka truss, dtrace, etc on various operating systems) the python process and watch all the open() system calls. See what paths it attempts to open when searching for blablabla. Sometimes that gives you insight into what's going wrong. > I have messed around for oven an hour and get nowhere. What temperature was the oven set at?
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-06-29 19:26 +0000 |
| Message-ID | <51cf3500$0$29999$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #49449 |
On Sat, 29 Jun 2013 19:13:47 +0000, Martin Schöön wrote:
> $PYTHONPATH points at both the code and the test directories.
>
> When I run blablabla_test.py it fails to import blablabla.py
What error message do you get?
> I have messed around for oven an hour and get nowhere. I have done
> unittesting like this with success in the past and I have revisited one
> of those projects and it still works there.
[...]
> Any leads?
The first step is to confirm that your path is setup correctly. At the
very top of blablabla_test, put this code:
import os, sys
print(os.getenv('PYTHONPATH'))
print(sys.path)
What do they say? What should they say?
The second step is to confirm that you can import the blablabla.py
module. From the command line, cd into the code directory and start up a
Python interactive session, then run "import blablabla" and see what it
does.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Martin Schöön <martin.schoon@gmail.com> |
|---|---|
| Date | 2013-06-29 21:19 +0000 |
| Message-ID | <b391b9Fl0dpU1@mid.individual.net> |
| In reply to | #49454 |
On 2013-06-29, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
> On Sat, 29 Jun 2013 19:13:47 +0000, Martin Schöön wrote:
>
>> $PYTHONPATH points at both the code and the test directories.
>>
>> When I run blablabla_test.py it fails to import blablabla.py
>
> What error message do you get?
>
>
>> I have messed around for oven an hour and get nowhere. I have done
>> unittesting like this with success in the past and I have revisited one
>> of those projects and it still works there.
> [...]
>> Any leads?
>
> The first step is to confirm that your path is setup correctly. At the
> very top of blablabla_test, put this code:
>
> import os, sys
> print(os.getenv('PYTHONPATH'))
> print(sys.path)
>
Yes, right, I had not managed to make my change to PYTHONPATH stick.
I said the explanation would be trivial, didn't I?
Thanks for the quick replies. I am back in business now.
No, neither English nor Python are native languages of mine but I
enjoy (ab)using both :-)
/Martin
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web