0

I'm doing some unit testing I'm coming from java world this is very basic for enabling unit tests.

I tried this as suggested in comments using StringIO however getting an error what am i doing wrong?

>>> import StringIO
>>> output = StringIO.StringIO()
>>> output.write('[general]\n')
>>> output.write('key=value\n')
>>> import ConfigParser
>>> config = ConfigParser.ConfigParser()
>>> config.read(output)
>>> config.items('general')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/ConfigParser.py", line 642, in items
    raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'general'

thanks

Jas
  • 14,493
  • 27
  • 97
  • 148
  • 1
    Use [StringIO](https://docs.python.org/2/library/stringio.html), which is a general API for using strings as file-like objects... – l4mpi May 19 '14 at 14:45
  • @l4mpi thanks, I edited the question and added a trial of mine to use `StringIO` what did i do wrong? thanks again. – Jas May 19 '14 at 14:57
  • @l4mpi got it needed to use `readfp` instead of `read` and also the double write does not work. thanks – Jas May 19 '14 at 15:01

0 Answers0