question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to simulate TDD with pytest

See original GitHub issue

I’m not sure how it is with previous versions, but with Python 3.7.3 and Pytest 5.0.1, tests are run in alphabetical order rather than in the order they appear in the test file. As I understand it, Exercism’s explicit pedagogical aim is to simulate TDD, and so it seems pretty important that the tests get run in the order they appear in the file such that pytest -x stops at the simplest of the failing test cases – i.e., the case a test-driven developer would have written first.

As it stands now, the first failing test is often for an edge case that isn’t really useful until the program’s basic functionality is up and running.

In the minitest files for the Ruby track, if I remember correctly, # skip lines are included for all but the first test, and the learner is instructed to uncomment the skip for the next test once they get a given test to pass.

I would imagine there’s a more elegant fix for this than simply going back through all the track’s test files and adding hundreds of # @pytest.mark.skipdecorators, but I’ve yet to figure out what it is. Maybe there’s some way to configure pytest to run the tests in the order they appear in the test file that I’m just unaware of? I’ve spent a couple of hours looking into this to no avail so far.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
yawpitchcommented, Mar 4, 2020

I just wanted to point out that it is possible to get unittest to run tests in whatever order you want using arbitrary functions…

And that’s helpful, however I’m of the mind we should close this Issue as wontfix because of that lack of guarantees in the upstream data. The canonical data repo is currently locked to major changes and it remains to be seen precisely how it will be incorporated into V3, so I don’t think we’re able to meaningfully move on this right now except by introducing something like that logic, which without those same guarantees really just slows down tests to provide a false sense of order.

Anyone strongly disagree with that?

1reaction
cmccandlesscommented, Mar 5, 2020

In favor of won't fix

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test-Driven Development in Python with Pytest
A test passes when the test function doesn't raise an exception. The test may fail for two reasons: AssertionError - if the condition...
Read more >
TDD in Python with pytest - Part 3 - The Digital Cat
Let me give you an example. Consider a web application and imagine a test that checks that a user can log in. ......
Read more >
Modern Test-Driven Development in Python - TestDriven.io
We used pytest's parametrize option, which simplifies passing in multiple inputs to a single test. Test should fail at this point because we ......
Read more >
Effective Python Testing With Pytest
When to Create Fixtures. In this section, you'll simulate a typical test-driven development (TDD) workflow. Imagine you're writing a function, ...
Read more >
How to test failed authentication attempts with test-driven ...
Mountebank makes it very easy to simulate a service that listens on a network ... This article has focused on test-driven development (TDD), ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found