Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate checking of readme in pytest

I use pytest in my .travis.yml to check my code.

I would like to check the README.rst, too.

I found readme_renderer via this StackO answer

Now I ask myself how to integrate this into my current tests.

The docs of readme_renderer suggest this, but I have not clue how to integrate this into my setup:

python setup.py check -r -s
like image 704
guettli Avatar asked Oct 16 '17 09:10

guettli


People also ask

How does pytest test discovery work?

pytest implements the following standard test discovery: If no arguments are specified then collection starts from testpaths (if configured) or the current directory. Alternatively, command line arguments can be used in any combination of directories, file names or node ids.

What are plugins in pytest?

pytest comes with a plugin named pytester that helps you write tests for your plugin code. The plugin is disabled by default, so you will have to enable it before you can use it. Alternatively you can invoke pytest with the -p pytester command line option.

Where do I put test pytest?

Pytest expects our tests to be located in files whose names begin with test_ or end with _test.py . Let's create a file called test_capitalize.py , and inside it we will write a function called capital_case which should take a string as its argument and should return a capitalized version of the string.


2 Answers

I think the simplest and most robust option is to write a pytest plugin that replicates what the distutils command you mentioned in you answer does.

That could be as simple as a conftest.py in your test dir. Or if you want a standalone plugin that's distributable for all of us to benefit from there's a nice cookiecutter template.

Ofc there's inherently nothing wrong with calling the check manually in your script section after the call to pytest.

like image 55
renefritze Avatar answered Oct 30 '22 19:10

renefritze


I check it like this now:

# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, unicode_literals, print_function

import os
import subx
import unittest

class Test(unittest.TestCase):
    def test_readme_rst_valid(self):
        base_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
subx.call(cmd=['python', os.path.join(base_dir, 'setup.py'), 'check', '--metadata', '--restructuredtext', '--strict'])

Source: https://github.com/guettli/reprec/blob/master/reprec/tests/test_setup.py

like image 4
guettli Avatar answered Oct 30 '22 18:10

guettli