samedi 22 août 2015

Unit testing in Python - two directories have homonym subdirs

I've come across a weird occurrence. I have two Django projects like this:

fcon
   index
      tests.py

tbg
   index
      tests.py

Then running ./manage.py test (with cd fcon) yields the traceback below. I went into the code and this is the culprit:

mod_file = os.path.abspath(getattr(module, '__file__', full_path))

This evaluates to (..)/tbg/index/tests.py. I guess it's only natural since this doesn't actually check what's above tests.py. Is there a solution for this besides renaming the apps?

Traceback (most recent call last):
  File "D:\Programs\PyCharm 4.5.3\helpers\pycharm\django_test_manage.py", line 129, in <module>
    utility.execute()
  File "D:\Programs\PyCharm 4.5.3\helpers\pycharm\django_test_manage.py", line 104, in execute
    PycharmTestCommand().run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\commands\test.py", line 30, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python27\lib\site-packages\django\core\management\commands\test.py", line 74, in execute
    super(Command, self).execute(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "D:\Programs\PyCharm 4.5.3\helpers\pycharm\django_test_manage.py", line 91, in handle
    failures = TestRunner(test_labels, verbosity=verbosity, interactive=interactive, failfast=failfast, keepdb='--keepdb' in sys.argv)
  File "D:\Programs\PyCharm 4.5.3\helpers\pycharm\django_test_runner.py", line 256, in run_tests
    extra_tests=extra_tests, **options)
  File "D:\Programs\PyCharm 4.5.3\helpers\pycharm\django_test_runner.py", line 156, in run_tests
    return super(DjangoTeamcityTestRunner, self).run_tests(test_labels, extra_tests, **kwargs)
  File "C:\Python27\lib\site-packages\django\test\runner.py", line 209, in run_tests
    suite = self.build_suite(test_labels, extra_tests)
  File "D:\Programs\PyCharm 4.5.3\helpers\pycharm\django_test_runner.py", line 120, in build_suite
    suite = super(DjangoTeamcityTestRunner, self).build_suite(*args, **kwargs)
  File "C:\Python27\lib\site-packages\django\test\runner.py", line 150, in build_suite
    tests = self.test_loader.discover(start_dir=label, **kwargs)
  File "C:\Python27\lib\unittest\loader.py", line 204, in discover
    tests = list(self._find_tests(start_dir, pattern))
  File "C:\Python27\lib\unittest\loader.py", line 285, in _find_tests
    for test in self._find_tests(full_path, pattern):
  File "C:\Python27\lib\unittest\loader.py", line 265, in _find_tests
    raise ImportError(msg % (mod_name, module_dir, expected_dir))
ImportError: 'tests' module incorrectly imported from 'D:\\development\\PyCharm\\Projects\\tbg\\index'. Expected 'D:\\development\\PyCharm\\Projects\\fcon\\index'. Is this module globally installed?

Aucun commentaire:

Enregistrer un commentaire