Skip to content

attribute error with unit test and temporary db #294

Open
@ghost

Description

Originally reported by: Anonymous


here is my setup.py file :

#!python

from setuptools import setup
from setuptools.command.test import test as TestCommand
import sys

class PyTest(TestCommand):
    user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]

    def initialize_options(self):
        TestCommand.initialize_options(self)
        self.pytest_args = []

    def finalize_options(self):
        TestCommand.finalize_options(self)
        self.test_args = []
        self.test_suite = True

    def run_tests(self):
        #import here, cause outside the eggs aren't loaded
        import pytest
        errno = pytest.main(self.pytest_args)
        sys.exit(errno)

setup(
    name='projectName',
    version='0.1',
    description='project description',
    url='',
    author='me',
    author_email='',
    license='',
    packages=['package1', 'package2'],
    zip_safe=False ,
    tests_require=['pytest'],
    cmdclass = {'test': PyTest}
)

So when running

#!shell

python setup.py test

It will launch all my unit tests. Everything is ok whith the tests that don't use a temporary db. Today i started to use a temporary postgresql db (module testing.postgresql) and now i have one AttributeError by test.

With pdb i get the stack trace :

#!python

Traceback (most recent call last):
  File "setup.py", line 36, in <module>
    cmdclass = {'test': PyTest}
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/test.py", line 135, in run
    self.with_project_on_sys_path(self.run_tests)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/test.py", line 120, in with_project_on_sys_path
    sys.modules.update(old_modules)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/test.py", line 120, in with_project_on_sys_path
    sys.modules.update(old_modules)
  File "/usr/lib/python2.7/bdb.py", line 49, in trace_dispatch
    return self.dispatch_line(frame)
  File "/usr/lib/python2.7/bdb.py", line 67, in dispatch_line
    self.user_line(frame)
  File "/usr/lib/python2.7/pdb.py", line 158, in user_line
    self.interaction(frame, None)
  File "/usr/lib/python2.7/pdb.py", line 209, in interaction
    self.print_stack_entry(self.stack[self.curindex])
  File "/usr/lib/python2.7/pdb.py", line 900, in print_stack_entry
    prompt_prefix)
  File "/usr/lib/python2.7/bdb.py", line 362, in format_stack_entry
    import linecache, repr
  File "/usr/lib/python2.7/linecache.py", line 9, in <module>
    import os
  File "/usr/lib/python2.7/os.py", line 119, in <module>
    sys.modules['os.path'] = path
AttributeError: 'module' object has no attribute 'modules'
Exception AttributeError: "'NoneType' object has no attribute 'getpid'" in <bound method Postgresql.__del__ of <testing.postgresql.Postgresql object at 0x7fc6481279d0>> ignored

that occurs on line 119 in setuptools/command/test.py

when running those tests with

#!shell

python myTest.py

I have no error.


Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions