Abhishek Arya
Abhishek Arya

Reputation: 500

Pytest: specifying multiple naming conventions for functions

I want to test functions in a class and for some reason I couldn't name them like test_*. This is how my class looks like:

class SegmentationSuite:
    """Benchmark for segmentation routines in scikit-image."""
    def setup(self):
        self.image = np.random.random((400, 400, 100))
        self.image[:200, :200, :] += 1
        self.image[300:, 300:, :] += 0.5

    def time_slic_basic(self):
        segmentation.slic(self.image, enforce_connectivity=False)

    def peakmem_setup(self):
        pass

    def peakmem_slic_basic(self):
        segmentation.slic(self.image, enforce_connectivity=False)

So, there are three sets of functions: time_*, setup and peakmem. After looking at the pytest docs, I found out https://docs.pytest.org/en/latest/example/pythoncollection.html#changing-naming-conventions

So, I created a setup.cfg file and added the following to it:

[tool:pytest]
python_files=benchmark_*.py
python_classes=*Suite
python_functions=time_*, setup, peakmem*

but it doesn't work.

How do I do this?

Thanks.

Upvotes: 0

Views: 736

Answers (1)

Abhishek Arya
Abhishek Arya

Reputation: 500

This is how I did it python_functions=time_* setup peakmem*. Specifying multiple glob patterns separated with blank space.

Upvotes: 1

Related Questions