Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango testing with assertRaises fails to realise that exception raised is the one expected
    primarykey
    data
    text
    <p>I have the following test code snippet</p> <pre><code>with self.assertRaises(models.NotEnoughInventorySpace): self.inv2.add_item(self.item2, 1) </code></pre> <p>The test fails:</p> <pre><code>Creating test database for alias 'default'... E. ====================================================================== ERROR: test_limited_inventory (wotw_project.game.tests.TestInventory) ---------------------------------------------------------------------- Traceback (most recent call last): File "D:\...\wotw\wotw_project\..\wotw_project\game\tests.py", line 34, in test_limited_inventory self.inv2.add_item(self.item2, 1) File "D:\...\wotw\wotw_project\..\wotw_project\game\models.py", line 460, in add_item raise NotEnoughInventorySpace(self) NotEnoughInventorySpace: There is not enough space in the inventory 'Inventory: 2' ---------------------------------------------------------------------- Ran 2 tests in 0.015s FAILED (errors=1) Destroying test database for alias 'default'... Finished "D:\...\wotw\wotw_project\manage.py test game" execution. </code></pre> <p>I do not see why the exception raised is not identical to the one I pass into <code>assertRaises</code></p> <p>I run the code using <code>manage.py test game</code> with uses the <code>tests.py</code> file next to my <code>models.py</code> file in <code>wotw_project.game</code>.</p> <p>My research into this problem shows that there may be a problem with imports (ie. the <strong>main</strong> file is different to the same file imported). However I am using the standard method to run the unittest so I do not see why this is a problem for only me, surely other people have used assertRaises with Django!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload