Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pytest tmpdir fixture #482

Merged
merged 7 commits into from
Dec 3, 2019

Conversation

neggert
Copy link
Contributor

@neggert neggert commented Nov 8, 2019

As mentioned in #463, replace manually creating and deleting save directories with the pytest tmpdir feature. This eliminates the need to manually clear out directories.

Right now, I've just done this for one of the test files. I want to get some feedback on the change before I spend the time to do the rest of them. @williamFalcon @Borda LMK if you agree that this is a good idea and I'll go ahead and do the rest.

@neggert
Copy link
Contributor Author

neggert commented Nov 12, 2019

Ping @williamFalcon @Borda any thoughts before I go ahead and update the rest of the tests?

@Borda
Copy link
Member

Borda commented Nov 13, 2019

I would use Unittests - https://docs.python.org/3/library/unittest.html where you can define some action on start and end, in this case, create temp folder and remove at the end, for example:

import os
import unittest
import uuid
import shutils

class TestCPUModels(unittest.TestCase):
    def setUp(self):
        self.tmp_dir = os.path.join(os.path.dirname(__file__), uuid.uuid4().hex)
        os.mkdir(self.tmp_dir)

    def test_early_stopping_cpu_model():
        ...
    def test_running_test_after_fitting():
        ...

    def tearDown(self):
        shutils.rmtree(self.tmp_dir)

@williamFalcon
Copy link
Contributor

williamFalcon commented Nov 13, 2019

@neggert sorry for the delay. Fairly busy 2 weeks.

I don't have strong feelings about either. unless one clearly outweighs the other.

@Borda i'm not sure your approach solves the issue? you need a new tmpdir for each test, not just a class of tests

@Borda
Copy link
Member

Borda commented Nov 13, 2019

@williamFalcon see the doc of unittests, it says "The setUp() and tearDown() methods allow you to define instructions that will be executed before and after each test method. They are covered in more detail in the section Organizing test code."
in contrast, there is "setUpClass() - A class method called before tests in an individual class are run. setUpClass is called with the class as the only argument and must be decorated as a classmethod()" and "tearDownClass() - A class method called after tests in an individual class have run. tearDownClass is called with the class as the only argument and must be decorated as a classmethod()"
so it will generate a unique temp folder for each test method... :)

@neggert
Copy link
Contributor Author

neggert commented Nov 13, 2019

@Borda pytest has similar functionality. No need to swap out our entire testing framework. I prefer pytest over unittest anyway.

Here I'm using a fixture that is built-in to pytest that does what you're describing. Pytest generates and deletes a temp folder for you.

@Borda
Copy link
Member

Borda commented Nov 13, 2019

@neggert it is not about swapping framework, unittest is just another functionality as well as doctests... I would call pytest as an ecosystem... where unit-tests belongs :)
btw, you probably missed the link...

@neggert
Copy link
Contributor Author

neggert commented Nov 13, 2019

I guess I'm not clear on why you're suggesting using unittest when we already have this functionality from our existing test framework. Maybe I'm missing your point.

I think the thing you're suggesting we use in unittest is exactly what this PR does using our existing pytest framework.

@williamFalcon
Copy link
Contributor

williamFalcon commented Nov 13, 2019

@neggert @Borda let's come back to this after the documentation and coverage is back up to speed.

While it's clear we have two really good options, let's go with the solution proposed by @neggert in the meantime while we look deeper into @Borda 's option.

I'd like to spend more time on game-changing features instead! :)

@neggert
Copy link
Contributor Author

neggert commented Nov 13, 2019

Sounds good. I'll go ahead and update the rest of the tests.

@neggert neggert changed the title (WIP) Use pytest tmpdir fixture Use pytest tmpdir fixture Nov 22, 2019
@neggert neggert marked this pull request as ready for review November 22, 2019 22:23
@neggert
Copy link
Contributor Author

neggert commented Nov 22, 2019

@williamFalcon I think this is ready to go. I don't have a GPU that can run the AMP tests, so I'd appreciate a double-check on those.

There's also something strange going on with the Comet logger test, but I'm not sure if it's related to this PR.

@neggert
Copy link
Contributor Author

neggert commented Nov 25, 2019

ping @williamFalcon. I think this is ready to merge.

@williamFalcon
Copy link
Contributor

@neggert sorry, just getting back online. mind rebasing?

@neggert
Copy link
Contributor Author

neggert commented Dec 2, 2019

Fixed the conflicts. Also figured out what's going on with the CometML logger. I'd like to leave that for a separate PR, if you don't mind.

@williamFalcon williamFalcon merged commit 62f6f92 into Lightning-AI:master Dec 3, 2019
@neggert neggert deleted the pytest_tmpdir_fixture branch December 3, 2019 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants