0

I'm encountering an error while attempting to run unit tests with unittest and coverage in Python 2.7 on a Windows 11 system using WSL (Windows Subsystem for Linux). The error message suggests an issue with finding the test case test_admin_ruta_total_posiciones within the tests module.

Error Message:

Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/__main__.py", line 12, in <module>
    main(module=None)
  File "/usr/lib/python2.7/unittest/main.py", line 94, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python2.7/unittest/main.py", line 149, in parseArgs
    self.createTests()
  File "/usr/lib/python2.7/unittest/main.py", line 158, in createTests
    self.module)
  File "/usr/lib/python2.7/unittest/loader.py", line 130, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python2.7/unittest/loader.py", line 100, in loadTestsFromName
    parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'test_admin_ruta_total_posiciones'

Context:

I'm running Python 2.7 within a WSL environment on Windows 11. My project structure includes a tests directory where test_admin_ruta_total_posiciones.py resides. This file contains several unit tests using unittest.

Code Snippet:

import unittest

class TestAdminRutaTotalPosiciones(unittest.TestCase):
    # Test methods...

What could be causing this AttributeError during test discovery with unittest in a Python 2.7 environment on WSL, and how can I resolve it to successfully run my tests with coverage?

Steps Taken:

  1. Verified that test_admin_ruta_total_posiciones.py contains valid test methods within a unittest.TestCase subclass.
  2. Confirmed the directory structure is correct and tests is recognized as a module within the WSL environment.
  3. Attempted to execute tests with coverage using the command coverage run -m unittest tests.test_admin_ruta_total_posiciones, resulting in the above error.

Expected Outcome:

I expect unittest to discover and execute the tests defined in test_admin_ruta_total_posiciones.py, while coverage should generate a coverage report without encountering errors.

Additional Notes:

  • The setUp method within TestAdminRutaTotalPosiciones initializes necessary dependencies (db_beta, etc.) and sets configuration flags (EJECUTAR).
  • Other test methods (test_soporte_sin_db, test_admin_db, etc.) within the same test class encounter similar issues during test discovery.
4
  • If you are only just learning the basics, you should probably ignore Python 2, and spend your time on the currently recommended and supported version of the language, which is Python 3.
    – tripleee
    Commented Jun 25 at 13:27
  • @tripleee I'm an intern and I've been told to improve the tests so that the coverage checks if anything fails when the program is in python 3, I know it's outdated but i don't have any other option
    – a_retr0
    Commented Jun 27 at 6:00
  • Thanks for clarifying. Going forward, it's probably a good idea to include an explanation like this in the question itself if you have similar circumstances where you need support for obsolescent technology or something else that is unusual.
    – tripleee
    Commented Jun 27 at 8:25
  • Sorry, it's just my first time using this because I haven't seen a solution anywhere.
    – a_retr0
    Commented Jun 28 at 8:33

0