Tests appear to be running in alphabetical order for Raindrops

Open
#2,214 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
testing

Research direction

Start with raindrops_test.py and reproduce the ordering using pytest -x raindrops_test.py. Compare the observed alphabetical order with the test definitions and the attempted unittest.TestLoader.sortTestMethodsUsing setting. Done means the exercise tests run in the intended progression, or the repository has a documented and consistent alternative.

Written by the indexing model from the issue text.

Description

discussion 💬 maintainer action required❕ smolder🍲

I tried out a couple of exercises on the Python track today, and noticed with the Raindrops exercise in particular that the tests were requiring me to implement the entire algorithm on the second failure.

I'm working in Python 3.8.5.

I run the tests with the following command:

pytest -x raindrops_test.py

With the unchanged stub file in place, I get the following failure:

    def test_2_to_the_power_3_does_not_make_a_raindrop_sound_as_3_is_the_exponent_not_the_base(
        self
    ):
>       self.assertEqual(convert(8), "8")
E       AssertionError: None != '8'

This is a reasonable "first" failure, since it's a single number that should be turned into a string.
If I make that pass with a hard-coded return "8", then this is the next failure I get:

    def test_the_sound_for_105_is_pling_plang_plong_as_it_has_factors_3_5_and_7(self):
>       self.assertEqual(convert(105), "PlingPlangPlong")
E       AssertionError: '8' != 'PlingPlangPlong'
E       - 8
E       + PlingPlangPlong

Looking at the tests, the order that they are defined in is quite nice, in terms of pushing the implementation forward step by step.

I tried adding the following declaration after the import unittest statement, to see if this would cause the tests to be run in the order that they are defined:

unittest.TestLoader.sortTestMethodsUsing = None

This did not change the order that the tests are run in.

If I sort the tests alphabetically by name, it appears to correspond to the order that I'm seeing when doing the exercise:

While under normal circumstances I would want tests to be run in random order, in Exercism exercises I think that it would make more sense to run the tests in the order that they are defined.

Is there a declaration we can make in order to accomplish this?
If not, then I would propose that we rename tests by adding a numeric prefix to the test name (e.g.

def test_01_the_sound_for_1_is_1(self):
Dominant language
Python
Stars
2.5k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from exercism/python

All issues in exercism/python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.