473,699 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

nose, doctest, and module names in subpackages

I'm trying to use both nosetests and doctest with the tests
pulled out into a separate file. My problem is that it
seems that I need to use different import statements
depending on from where I run the tests.

Here's my directory structure:
test_code_file. py

--- code_file.py: ---
def example_functio n():
return 0

--- test_code_file. py ---
def run_tests():
import doctest
result=doctest. testfile("tests .txt")
assert result[0] == 0

if __name__ == "__main__":

--- tests.txt ---
>>from code_file import example_functio n
With this, nosetests works when run from /dir/sub, but
the import fails if nosetests is run from /dir.

If I change tests.txt to

--- tests.txt ---
>>from sub.code_file import example_functio n
(adding "sub.") then nosetests works from /dir, but not
from /dir/sub. And in this case "python test_code_file. py"
fails when run from /dir/sub.

In general, I would like to run doctests during development
from the directory where the code lives, leading me to
prefer "from code_file import", but I would like to run
nosetests from the top of the tree, leading me to want
"from sub.code_file import".

I played around with variations like using doctest.DocFile Suite
and nosetests' --with-doctest option, but nothing I tried
helped with the basic issue of the name of the module
varying depending on the execution directory.

It seems I'm missing something very basic here. Any tips
would be much appreciated.

(I'm running python 2.4.1 and nosetests 0.9.0)


Sep 6 '06 #1
0 1204

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Pierre Rouleau | last post by:
I have a problem writing self-testable modules using doctest when these modules have internationalized strings using gettext _('...'). - The main module of an application (say app.py) calls gettext.install() to install the special _ function inside Python builtin. Other modules, taken from a general purpose collection of Python modules, also support internationalisation and doctest testing. For example:
by: Alan G Isaac | last post by:
> python doctest.py -v Running doctest.__doc__ Trying: .remove(42) Expecting: Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: list.remove(x): x not in list ok Trying: x = 12 Expecting: nothing
by: john_sips_tea | last post by:
For writing testcode, it looks like there's three ways that it's typically done: (1). using the doctest module, (2). using the unittest module (i.e. "pyunit"), or else (3). just putting an "if __name__ = '__main__':" at the bottom of your module containing code to manually run your class through its paces.
by: Stuart D. Gathman | last post by:
I am trying to create a doctest test case for the following: def quote_value(s): """Quote the value for a key-value pair in Received-SPF header field if needed. No quoting needed for a dot-atom value. '"abc\\\\\\\\def"' '"abc..def"' '""' '"-all\\\\\\\\x00"'
by: thomas.guest | last post by:
I'm not making progress with the following and would appreciate any help. Here's an interpreted Python session. .... Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'f' is not defined
by: Bzyczek | last post by:
Hello, I have problems with running doctests if I use czech national characters in UTF-8 encoding. I have Python script, which begin with encoding definition: # -*- coding: utf-8 -*- I have this function with doctest:
by: petr.jakes.tpc | last post by:
Hi, inspired by the article written by Tarek Ziade in the February 07 issue of the "Linux +" magazine I am experimenting with the doctest module. I have two files, "displeje_pokus.py" and "displeje_pokus.txt" (you can see the simplified contents of the files bellow). When I run "python displeje_pokus.py" I am getting an error (see
by: Steven D'Aprano | last post by:
I have a function in my module: def selftest(verbose=False): import doctest doctest.testmod(verbose=verbose) When I run it, it fails to find any of my doc tests, including the tests in __main__, and in fact it looks like it can't even find my functions and classes:
by: =?iso-8859-1?q?KLEIN_St=E9phane?= | last post by:
Hi, for example, in http://svn.zope.org/zc.buildout/trunk/src/zc/buildout/ tests.py?rev=89831&view=auto test file, there is this doctests : def develop_verbose(): """ We should be able to deal with setup scripts that aren't setuptools based. ... '''
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.