EECS 485 Lab

EECS 485 Lab 4: Server-side Dynamic Pages Tools

Due: 8:00pm EST September 27, 2020.


Browser Development Tools

Review browser tools, you’ll still need those.

Complete the two new sections in the tutorial on Cookies and Private Browsing. Do not complete the JavaScript debugger section, we’ll cover that in the future.

Python tools

First, refresh yourself on pdb++ and and pytest.

Now let’s run through an example of how to use pdb and pytest together.

Make sure your virtual environment is activated and you have Pdb++ installed in your virtual environment.

$ pip install pdbpp

For the purpose of this tutorial, we’ll add a failure to one of the project 2 tests. Edit sql/schema.sql and make an intentional typo. Change username to uuusername`.

  uuusername VARCHAR(20) NOT NULL,

Run the database tests. They should fail.

$ pytest -v tests/
============================== 2 failed in 0.12s ===============================

Run the tests again, but with pytest’s -x flag, which will stop after the first failure.

$ pytest -v tests/ -x
============================== 1 failed in 0.11s ===============================

Run the test again, adding pytest’s --pdb flag, which still start a debugger at the line of the failure.

$ pytest -v tests/ -x --pdb

Start Pdb++’s sticky mode, which will show you the function where the exception occurred and also highlights the line that threw the error.

(Pdb++) sticky
  10     def test_sql_schema(db_connection):
  11         """Verify schema.sql produces correct tables.
  13         Note: 'db_connection' is a fixture fuction that provides an empty,
  14         in-memory sqlite3 database.  It is implemented in and r
  15         many tests.  Docs:
  16         """
  17         # Load student schema.sql
  18         with open("sql/schema.sql") as infile:
  19             schema_sql =
  20         assert "PRAGMA foreign_keys = ON" in schema_sql
  21  ->     db_connection.executescript(schema_sql)                            
  22         db_connection.commit()                                             

Now, use pdb features like continue, print, and more to debug why your code is failing the tests.

Try using the p command to print a variable.

(Pdb++) p schema_sql

Quit Pdb++.

(Pdb++) q

Run the test again, using the --trace flag, which still start a debugger at the beginning of the test. Start sticky mode.

$ pytest -v tests/ -x --trace
(Pdb++) sticky

Step through the test line-by-line until you reach the failure. Next line is n in Pdb. Pro-tip: just keep hitting enter after entering a single n. The default is to repeat the previous command.

(Pdb++) n
(Pdb++) n
(Pdb++) n

Now that you’ve practiced with some of the features of pytest, don’t forget to fix the SQL typo we inserted.

Completion Criteria

Lab Quiz

Complete the lab quiz by the due date.