OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

AttributeError when running unittest with coverage in Python 2.7 on WSL

  • Thread starter Thread starter a_retr0
  • Start date Start date
A

a_retr0

Guest
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:​


Code:
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:​


Code:
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.
<p>I'm encountering an error while attempting to run unit tests with <code>unittest</code> and <code>coverage</code> 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 <code>test_admin_ruta_total_posiciones</code> within the <code>tests</code> module.</p>
<h3>Error Message:</h3>
<pre><code>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'
</code></pre>
<h3>Context:</h3>
<p>I'm running Python 2.7 within a WSL environment on Windows 11. My project structure includes a <code>tests</code> directory where <code>test_admin_ruta_total_posiciones.py</code> resides. This file contains several unit tests using <code>unittest</code>.</p>
<h3>Code Snippet:</h3>
<pre class="lang-py prettyprint-override"><code>import unittest

class TestAdminRutaTotalPosiciones(unittest.TestCase):
# Test methods...
</code></pre>
<p>What could be causing this <code>AttributeError</code> during test discovery with <code>unittest</code> in a Python 2.7 environment on WSL, and how can I resolve it to successfully run my tests with <code>coverage</code>?</p>
<h3>Steps Taken:</h3>
<ol>
<li>Verified that <code>test_admin_ruta_total_posiciones.py</code> contains valid test methods within a <code>unittest.TestCase</code> subclass.</li>
<li>Confirmed the directory structure is correct and <code>tests</code> is recognized as a module within the WSL environment.</li>
<li>Attempted to execute tests with coverage using the command <code>coverage run -m unittest tests.test_admin_ruta_total_posiciones</code>, resulting in the above error.</li>
</ol>
<h3>Expected Outcome:</h3>
<p>I expect <code>unittest</code> to discover and execute the tests defined in <code>test_admin_ruta_total_posiciones.py</code>, while <code>coverage</code> should generate a coverage report without encountering errors.</p>
<h3>Additional Notes:</h3>
<ul>
<li>The <code>setUp</code> method within <code>TestAdminRutaTotalPosiciones</code> initializes necessary dependencies (<code>db_beta</code>, etc.) and sets configuration flags (<code>EJECUTAR</code>).</li>
<li>Other test methods (<code>test_soporte_sin_db</code>, <code>test_admin_db</code>, etc.) within the same test class encounter similar issues during test discovery.</li>
</ul>
 

Latest posts

B
Replies
0
Views
1
Blundering Ecologist
B
Top