私は奇妙な状況にあります。私は次のようなコードを持っています(Z.Shaw Learn the python the hard wayから):
WORD_TYPES={
   'verb' : ['go', 'kill', 'eat'],
   'direction' : ['north', 'south', 'east', 'west'],
   'noun' : ['bear', 'princess'],
   'stop' : ['the','in','of'],
   'adjective': ['beautiful','cool','nice']
   }
VOCABULARY={word: word_type for word_type, words in WORD_TYPES.items() for word in words}
def scan(sentence):
    tokens=[]
    for word in sentence.lower().split():
        try:
            word_type=VOCABULARY[word]
        except KeyError:
            try:
                value=int(word)
            except ValueError:
                tokens.append(('error',word))
            else:
                tokens.append(('int',word))
    else:
        tokens.append((word_type,word))
    for i in range(0,len(tokens)):
         if tokens[i][0] == "error":
            del tokens[i]
return tokens
「美しい」という言葉で試してみると、期待どおりに返されます
[('adjective', u'beautiful')]
しかし、ノーズテストでは予測できない結果が得られ、その理由がわかりません。
from nose.tools import *
from Ex_48 import lexicon
def test_upper_lower_letters():
    assert_equal(lexicon.scan("Beautiful"),[('adjective','beautiful')])
    assert_equal(lexicon.scan("BEauTiful"),[('adjective','beautiful')])
これは私が得るものです:
C:\Python27\projects\skeleton\tests>nosetests tests_Ex_48
.......F
======================================================================
FAIL: tests_Ex_48.test_upper_lower_letters
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\nose-1.3.0-py2.7.egg\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "C:\Python27\projects\skeleton\tests\tests_Ex_48.py", line 58, in test_upper_lower_letters
    assert_equal(lexicon.scan("Beautiful"),[('adjective','beautiful')])
AssertionError: Lists differ: [('error', 'Beautiful')] != [('adjective', 'beautiful')]
First differing element 0:
('error', 'Beautiful')
('adjective', 'beautiful')
- [('error', 'Beautiful')]
+ [('adjective', 'beautiful')]
----------------------------------------------------------------------
Ran 8 tests in 0.002s
FAILED (failures=1)
助けてください