pypa / pypa/setuptools

attribute error with unit test and temporary db

Open
#294 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug minor
Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

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.


Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with setuptools/command/test.py around line 119 and reproduce the difference between python setup.py test and python myTest.py using the temporary PostgreSQL setup. Inspect how the test command restores sys.modules and how the temporary database is cleaned up; done means the test command no longer raises the AttributeError or cleanup exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
build-system, databases, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.