small medium large xlarge

02 Dec 2016, 18:08
Ari Davidow (2 posts)

I cannot replicate what I am seeing in Figure 4, Ch 6, with regards to doctest.

  1. I =think= I am running a duplicate of the code listing for When I import it into IDLE (I am running python 3.4.1), first I don’t see the default actions take place (because it is running as a module, not from the command line, I presumed), so that doesn’t match Fig. 4.

  2. When I import and run doctest, I get “attempted=0”, not “attempted=1” as shown in the diagram. This makes sense, because no test appears to be running. It also indicates that I am doing something differently.

  3. In your test, you note that: TestResults(failed=0, attempted=1) indicates that three tests were run. Is that a typo? There =are= three tests in the file.

  4. following some direction on the web, if I add “import doctest” into my, and then place the line, “doctest.testmod()” as the first item after the “if … main” and run the module from the command line, I get a. nothing returned when the code is correct–which both python and wikipedia say is correct when run via CLI b. an appropriate error message when I follow the text and remove the parens that make the conversion to celsius work correctly.

So, I think my code is generally correct, but something is happening in IDLE that I have configured differently/incorrectly such that what I observe does not match the text.


31 Dec 2016, 16:56
Ari Davidow (2 posts)

I had hoped for a response earlier, but here is what I have learned since I posted.

  1. Figure 4 must be in error–there =are= three tests being performed.
  2. As displayed in figure 4, (presumably, after has been imported) what would be seen is:
    >>> 'TestResults(failed=0, attempted=0')

The problem is that testmod is effectively testing “none”. The correct command would be:

    TestResults(failed=0, attempted=3')
  1. This is especially tricky to test from the command line, as normal python respond to “no errors” is simply not to report any results–silence == success.

In general, I am sometimes finding the figures showing idle to be confusing, as it can be unclear what the previous state was prior to whatever typing sequence is shown.

Hope this is eventually confirmed by authors, and that it helps other people as confused as I have been.

You must be logged in to comment