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

Support non-unittest class decoration #187

Closed
wants to merge 2 commits into from

Conversation

leokon
Copy link

@leokon leokon commented Sep 29, 2021

Contributes towards #20 by allowing any class to be decorated.

All methods starting with test on a decorated class are wrapped.

So that it's easier to re-use callable decoration as part of the
updated class decorator.
Wraps all class methods that begin with "test", matching default
pytest method collection.
@adamchainz
Copy link
Owner

adamchainz commented Oct 5, 2021

Is your motivation for this feature to use it with test classes in pytest? Because it's already very possible with the existing fixture like:

import time

import pytest


class TestSomething:
    @pytest.fixture(autouse=True)
    def set_time(self, time_machine):
        time_machine.move_to(1000)
        yield

    def test_one(self):
        assert int(time.time()) == 1000

    def test_two(self, time_machine):
        assert int(time.time()) == 1000
        time_machine.move_to(2000)
        assert int(time.time()) == 2000

Perhaps we could document that instead.

I worry that decorating a pytest class not affecting its setup/teardown/fixtures is counterintuitive, and would be hard to move to in the future.

@codecov-commenter
Copy link

Codecov Report

Merging #187 (f5baf51) into main (df41aec) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #187   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          241       253   +12     
  Branches        41        46    +5     
=========================================
+ Hits           241       253   +12     
Impacted Files Coverage Δ
src/time_machine/__init__.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update df41aec...f5baf51. Read the comment docs.

@adamchainz
Copy link
Owner

Closing due to lack of response.

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