Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Writing and Running Doctests: ValueError when just running python -m doctest

I was following along with "Writing and Running Doctests" in my local Terminal and when I ran python -m doctest dd_game.py, I got these errors that weren't pointing to the file I was testing.

When I ran it again without dd_game.py I was getting similar errors. Do I need to reinstall Python or something?

python -m doctest
Traceback (most recent call last):
  File "/Users/atotalpirate/Sites/_app/python/logging.py", line 4, in <module>
    [1, 2, 3].remove(4)
ValueError: list.remove(x): x not in list

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/doctest.py", line 105, in <module>
    import unittest
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/__init__.py", line 59, in <module>
    from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/unittest/case.py", line 6, in <module>
    import logging
  File "/Users/atotalpirate/Sites/_app/python/logging.py", line 6, in <module>
    logging.error("tried to remove an invalid value")
AttributeError: module 'logging' has no attribute 'error'

2 Answers

Hello Jimmy,

the track cleary states where the error came from:

/Users/atotalpirate/Sites/_app/python/logging.py", line 4
[1, 2, 3].remove(4)
ValueError: list.remove(x): x not in list

There also seems to be an error with your logging which is reported at the very bottom: You should not give a reserved name such as 'logging.py' to your own files: the logging python module is not recognized here, since Python takes your file as an overwrite of the build in logging module.

File "/Users/atotalpirate/Sites/_app/python/logging.py", line 6, in <module>
    logging.error("tried to remove an invalid value")
AttributeError: module 'logging' has no attribute 'error'```

I was also in the wrong virtualenv.

Shame

Thanks for your answer!