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.

Documentation: `setup` and `teardown` aren't mentioned

See original GitHub issue

While browsing the current release docs on “xunit-style” support, specifically the usage of setup and tearing down (cleanup) of tests, I was surprised not to see setup() and teardown() mentioned. Instead, the documentation points out that for methods, one must use setup_method() and teardown_method().

I’ve always used setup() and teardown() methods for setting up and cleaning up before and after each test method in a class for production code as well as teaching Pytest.

Are those methods deprecated and shouldn’t be used? Supported by mistake? Or is it an omission in the docs? Either way the docs need to be rectified for correctness. I’m happy to provide a PR with the right path.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
nicoddemuscommented, Jan 26, 2022

Hi @alfredodeza,

Fair question.

setup and teardown work because of the nose-style support.

For example, the example below works when executing pytest, but fails with pytest -p no:nose:

class Test:

    def setup(self):
        self.x = 1

    def test_foo(self):
        assert self.x == 1

So this is a nose-idiom, not a pytest-idiom.

Perhaps we need to document setup() and teardown() more explicitly in the nose page? 🤔

1reaction
nicoddemuscommented, Jan 26, 2022

but would like to have something to correlate to Nose (couldn’t find a reference)

Not sure either, I’m not familiar with nose’s docs myself, but it certainly is supported:

# test_foo.py
class Test:

    def setup(self):
        self.x = 1

    def test_foo(self):
        assert self.x == 1
λ pip list
Package    Version
---------- -------
nose       1.3.7
pip        21.3.1
setuptools 59.6.0
wheel      0.37.1

λ nosetests test_foo.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
Read more comments on GitHub >

github_iconTop Results From Across the Web

Teardown Clarification and/or Feature Request #1078 - GitHub
In the documentation, teardown is mentioned several times, but a clear example is never provided. I would assume that code written after a...
Read more >
Using Setup and Teardown Functions - Parasoft Documentation
You can perform test case setup and cleanup actions using setUp and tearDown functions. setUp and tearDown are called before and after each ......
Read more >
Setup And Teardown Scripts | ReadyAPI Documentation
Opens the Code Completion prompt. Go to Line, Moves the caret to the specified line. Show Line Numbers, Toggles whether line numbers are...
Read more >
How do I correctly setup and teardown for my pytest class with ...
According to Fixture finalization / executing teardown code, the current best practice for setup and teardown is to use yield instead of return...
Read more >
addTeardownBlock: | Apple Developer Documentation
Use teardown blocks to write test-specific teardown code alongside associated setup code. For example, if a test method needs to create a resource...
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