How to do a PyTest setup?

While going over questions/answers I came across @Michael question in LPTHW Ex46 : Nosetests succesful but cant understand what to do next on using nose/pytest.

I have been struggling with learning Nose from the book, even though its been deprecated, or trying pytest.
I don’t know if Mr Shaw will make a tutorial on pytest or just a

Either way I hope @Michael doesn’t mind me hijacking his question. I just thought I would get the ball rolling.

Thank you @zedshaw fo all you do.

Perfect, ok give me like one day and I’m going to write out instructions here temporarily, you can try them, and then if they work I’ll update the book.

1 Like

Good morning sir. Just dropping you a line to see how’s pytest is going. Don’t mean to bug you. I’m also not in a real hurry. Work n life has me on so inconsistent that I’ve scraped everything and have been going ground up on the basics. But I’ll be back in the 40’s soon enough.
Thank you again.

I managed to get pytest up and running (I think). FWIW, I am sharing what I have done here in brief bullet points.

  • Install pytest from Terminal - pip install -U pytest
  • Change your test file names from * to *
  • Replace the import at the beginning of the test from nose to pytest with an import pytest
  • Replace your assert_equal() statements to assert ’ == ’ NOTE: Drop the brackets
    E.g. assert_equal(center.go('north') , north) turns into assert center.go('north') == north
  • Run your tests from the project directory (one level above the test folder) using the command ‘$pytest’ instead of the command ‘$nosetests’

Doing these steps appeared to run the tests correctly on my machine, but I am no expert here.

A free service run by Zed A. Shaw for