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:
- Verified that
test_admin_ruta_total_posiciones.py
contains valid test methods within aunittest.TestCase
subclass. - Confirmed the directory structure is correct and
tests
is recognized as a module within the WSL environment. - 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 withinTestAdminRutaTotalPosiciones
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.