The Test Framework

This class will be using Python 3. If you don’t have Python 3 installed, please visit the official Python downloads page and click the yellow “Download Python 3.7.1” button. If you have any problems installing, please ask. Throughout this workshop we’ll be using a test framework to check your code. Here’s what you need to know to make it all work.

Download exercise test files. When unzipped, it should create a new folder called exercises. It contains the test framework we will be using, so you will be working from this folder.

Where to write your code

At the beginning of each exercise you’ll see a note describing where to find it. The exercises will be functions you’ll write or modify in the existing .py files in the exercises directory. It’s important that you write your code in the right place, or the tests won’t work.

How to run the tests

Once you’ve written your code and you’re ready to test it, we will use Python to run test.py followed the name of the exercise in your command prompt. Always type these commands from the exercises directory. The test framework knows where to find the files you tell it to test.

How you run this at the terminal will depend on your operating system and which version(s) of Python you have installed.

If you only have one version of Python installed, and it is Python 3, you can run the tests (for example) for the get_vowel_names exercise in lists.py like this:

Linux/Mac terminal:

$ python test.py get_vowel_names

Windows command window:

> py test.py get_vowel_names

If you have more than one version of Python installed, you’ll need to specify Python 3 like this:

Linux/Mac terminal:

$ python3 test.py get_vowel_names

Windows command window:

> py -3 test.py get_vowel_names

Passing the Tests

If your code has passed the tests, you’ll see some variation of this message:

Testing get_vowel_names

...
----------------------------------------------------------------------
Ran 3 tests in 0.002s

OK

Getting Help

You can also type python test.py (or python3 test.py or py -3 test.py) by itself, to see helpful documentation.

Please select a thing to test

iterators:

first: Return the first item in given iterable.
is_iterator: Return ``True`` if given iterable is an iterator.

functions:

around: Yield a tuple of the previous, current, and next items.
deep_flatten: Flatten an iterable of iterables.
pairwise: Yield a tuple containing each item and the item following it.
stop_on: Yield from the iterable until the given value is reached.
unique: Yield iterable elements in order, skipping duplicate values.
...
Write more Pythonic code

I send out 1 Python exercise every week through a Python skill-building service called Python Morsels.

If you'd like to improve your Python skills every week, sign up!

You can find the Privacy Policy here.
reCAPTCHA protected (Google Privacy Policy & TOS)