Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82122

Re: module import questions and question about pytest and module imports

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'sys': 0.07; 'meantime,': 0.09; 'stating': 0.09; 'subject:module': 0.09; 'subject:question': 0.10; 'python': 0.11; "wouldn't": 0.14; '__init__.py': 0.16; 'exception?': 0.16; 'imports': 0.16; 'pytest': 0.16; 'pytest,': 0.16; 'say.': 0.16; 'setuptools': 0.16; 'subject: \n ': 0.16; 'subject:import': 0.16; 'subject:questions': 0.16; 'sys.path': 0.16; 'url:whatsnew': 0.16; 'varies': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'trying': 0.19; 'seems': 0.21; '>>>': 0.22; 'import': 0.22; 'putting': 0.22; 'saying': 0.22; 'header:User- Agent:1': 0.23; '2.x': 0.24; 'directory.': 0.24; 'module,': 0.24; "haven't": 0.24; 'environment': 0.24; "i've": 0.25; 'this:': 0.26; 'post': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'point': 0.28; 'am,': 0.29; 'generally': 0.29; 'dec': 0.30; 'relative': 0.30; 'specified': 0.30; 'statement': 0.30; 'getting': 0.31; 'directory,': 0.31; 'url:python': 0.33; 'running': 0.33; 'guess': 0.33; "can't": 0.35; 'add': 0.35; 'there': 0.35; 'version': 0.36; 'module.': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'so,': 0.37; 'work?': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'read': 0.60; 'dave': 0.60; 'most': 0.60; 'url:5': 0.61; 'details.': 0.61; "you're": 0.61; 'back': 0.62; "you'll": 0.62; 'between': 0.67; 'hang': 0.67; 'received:74.208': 0.68; 'sam': 0.68; 'statement,': 0.68; 'bundling': 0.84; 'choices,': 0.84; 'me!': 0.84; 'off,': 0.84; 'received:74.208.4.194': 0.84; 'angel': 0.91; 'examine': 0.93
Date Mon, 08 Dec 2014 08:16:53 -0500
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0
MIME-Version 1.0
To python-list@python.org
Subject Re: module import questions and question about pytest and module imports
References <CAPti5iMacuhtNhGg_YkqdkW+X36R6bzRTo_RWn-KMq0CwczAOQ@mail.gmail.com> <54847FAF.8040006@davea.name> <CAPti5iPBG_YiG-ZUu_ZQD8qdg91Oq_6CXoJ-9t9vRFwtNYL4rA@mail.gmail.com>
In-Reply-To <CAPti5iPBG_YiG-ZUu_ZQD8qdg91Oq_6CXoJ-9t9vRFwtNYL4rA@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:lz5SjjQL7kF+hNzL7SHpIkKh5AEyPQt2B9Ipd4s4azx RfvyuLzQpv8PcmdsZFDkFVWtrXo/1P0PY0RRvGATzgwT27jsOf XS+KE2s6c7YGxqUS8rUG0kSlPG6zU3MJf6sJcjNfhOkAA8Ohvh oz3VICxJin89TxVSG5Jp6AOlEjiQ1Os4Eaq4ei7ycjHn4yTCjr APJcQ2KKXcYZw0DoXglhhl8cKXHaLkazklU5+eRQ8r5ajdP5hB zo+KH+0ZTP/siji3wZL2vF3iFLCilbsUkaKoKpwJ/tmM3L/wau 3a1th8K2O2mEdOhV3HJqHZYiqpkWK2G1jU/Y11FaQyMkY4ACTL /hPQpAE7waO69fGuxVoY=
X-UI-Out-Filterresults notjunk:1;
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16721.1418044627.18130.python-list@python.org> (permalink)
Lines 66
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1418044627 news.xs4all.nl 2966 [2001:888:2000:d::a6]:53271
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:82122

Show key headers only | View raw


On 12/07/2014 11:50 AM, sam pendleton wrote:
> Thanks for getting back with me!
>
> On Sun, Dec 7, 2014 at 11:26 AM, Dave Angel <davea@davea.name> wrote:
>> On 12/05/2014 11:50 PM, sam pendleton wrote:
>>>
>>> garage/
>>>       |- __init__.py
>>>       |- cars/
>>>           |- __init__.py
>>>           |- hummer.py
>>> tests/
>>>       |- test_cars.py
>>>
>>> at the top of test_cars.py, there is this:
>>>       from garage.cars import hummer
>>>
>>> pytest is on this import statement, so i guess it's incorrect.
>>
>>
>> No idea what that statement is trying to say.
>
> Sorry Dave, I was saying that pytest is hung up there stating it can't
> import that module.

Why don't you just try running the module, and post the stacktrace when 
it gets an exception?  I've never used pytest, and don't know why it 
would hang on any particular line.

>
>
>> If you're going to import something, it either has to be on the sys.path, or
>> in the current directory.  Is garage/ on your sys.path?
>>
>> You can examine sys.path  by
>>     import sys
>>     print(sys.path)
>
> Having to put the garage package on the sys.path seems a little off,
> why wouldn't relative imports work?
>
> Do most people somehow put their packages in sys.path when bundling
> their python packages up to be shared with setuptools or other python
> package managers? If so, how?
>

When you get to the point of bulding a distribution, you'll be putting 
your packages in the dist_packages directory, which is on sys.path. 
However, generally your distribution utility will handle those details.

In the meantime, you can set some environment variable to add locally to 
your sys.path.

As for relative import versus other choices, that varies between Python 
2.x and 3.x, and you haven't specified exactly what Python version 
you're running or what OS you're on.

In Python 2.x, relative import was considered to be ambiguous, and 
people figured it had to change.  You might want to read

https://docs.python.org/2.5/whatsnew/pep-328.html


-- 
-- 
DaveA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: module import questions and question about pytest and module imports Dave Angel <davea@davea.name> - 2014-12-08 08:16 -0500

csiph-web