Coder Social home page Coder Social logo

Comments (5)

picnixz avatar picnixz commented on August 15, 2024

After some thoughts, here is the interface that I could suggest:

  • first, this special decorator should never be merged in PRs unless there's a good reason (but I don't see which reason we could have since it would only be used with mixin classes parametrized by different interfaces)

  • since most of the time, everything is based according to a class attribute of the mixin class, it'd be easier to use:

    # skip if 'self.something' raises AttributeError, 
    # or if the C implementation of 'self.something' is missing. 
    @test.support.ignore_missing_impl(something="c") 
    def test_something(self):
        x = self.something(...)

I still don't know how to elegantly skip tests where a method is not implemented in C but is implemented in Python without having a complex interface. One idea is to have some generic predicate like:

def test(self):
	x = self.something_in_c_and_python(...)
	# assume that x.foo() exists only in Python
	
	# would call self.skipTest() if x.c does not exist
	# and if x is an object from a C module instead.
	# Usually the files import both the C and Python implementations,
	# so we could check whether x is from the C or the Python implementation like that.
	test.support.check_support(self, x, c='foo', pymodule=_pymodule, cmodule=_cmodule)
    y = x.foo()

from cpython.

terryjreedy avatar terryjreedy commented on August 15, 2024

I think you should just comment out or explicitly skip tests that are currently inapplicable. As you add pieces of the C implementation, you want them tested, so uncomment/unskip that tests that should pass with the new code addition.

from cpython.

picnixz avatar picnixz commented on August 15, 2024

@terryjreedy Actually, after a good sleep, I observed that a simpler solution is just to add a check inside the test like

if self.myclass is not _pyio.BytesIO:
	self.skipTest("TODO")

Ideally, I'd like to have the possibility of having self.skipIf(self.myclass is not _pyio.BytesIO) but there is only a skipIf decorator and not a skipIf method. Would it make sense to expose some skipIf method to the unittest class as well?

Anyway, I'll close this one as not planned.

from cpython.

terryjreedy avatar terryjreedy commented on August 15, 2024

I don't see the purpose of a method. What would it skip? The decorator skips what it contains and skipTest skips what contains it. That seems to cover the needed cases pretty well.

from cpython.

picnixz avatar picnixz commented on August 15, 2024

The issue with the decorator is that I cannot make it skip something that depends on an attribute, i.e., I cannot use self of something (at least, I don't see how I can put a skipIf decorator on a base class method which is then inherited by C or Python interfaces).

Maybe an example would be more explicit:

class MixinClass:
    myclass = None

    def test_this(self):
        x = self.myclass(...)

	def test_incomplete_component_for_now(self):
		# test is implementation agnostic
		if self.myclass is not MyPythonClass:
			self.skipTest("not ready for this test")

	# I would like to use `skipIf` like that:
	def test_incomplete_component_for_now_with_skipif(self):
		# self.skipIf does not exist as method on test cases!
		# and I cannot use the decorator on base mixin classes
		self.skipIf(self.myclass is not MyPythonClass)

class PythonTestSuite(MixinClass):
    myclass = MyPythonClass

class CTestSuite(MixinClass):
    myclass = MyCClass

Note that I don't want to disable the entire test suite of C classes, just specific tests on mixin classes, but I expected that skipIf would also be available as a method actually (it's more synctatic sugar but I understand if you don't want that additional interface).

from cpython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.