[TIP] Struggling with nose-to-pytest config file
nicoddemus at gmail.com
Tue May 1 07:38:31 PDT 2018
On Tue, May 1, 2018 at 10:56 AM Skip Montanaro <skip.montanaro at gmail.com>
> I'm moving from nose to pytest and am struggling a bit to get a
> working/useful config file. I renamed .noserc to pytest.ini and didn't
> change anything. Things seemed to work okay, but various bits of
> functionality are missing (output's not verbose, doctests aren't run,
> xunit/junit output not generated). I was a bit worried that it was ignoring
> my config file (even though it reports finding it).
> Here's one basic example. When I use --verbose on the command line, I get
> the expected verbose output, one line per test. If I give
> in the ini file, I get no verbose output, just the one dot per test. I also
> tried verbosity=1 and verbosity=2 to no avail. In addition, none of those
> three settings provoked an error message from pytest. Pytest never
> complains about anything. It seems to silently ignore everything.
> In general, it's not clear how I do the following:
> 1. Translate old .noserc settings into pytest-speak
> 2. Move settings off the command line into the config file. (I see the
> addopts thing, but aren't there equivalent configuration settings for the
> command line flags?)
You are correct, the proper way is to use `addopts` to always pass some
options to pytest as if they were typed in the command line. From that you
said at the start it seems this is a good start:
addopts = -v --doctest-modules --junitxml=tests.xml
As a rule pytest doesn't mimic all command-line options as a separate ini
setting, as it seems to be the case with nose.
You can see all ini settings in the reference docs:
> Google failed me. I saw some blog posts about converting from nose to
> pytest, but didn't see any discussion about the translation of
> configuration settings. Does pytest have some kind of magic
> "--generate-config" flag which will spit out a pytest.ini file with all the
> default values?
It doesn't currently, but I think such a flag could indeed be useful.
Right now it also doesn't display any message about unknown settings; I
think that is because since plugins can add new config settings, it might
happen that an user doesn't have a plugin installed but their pytest.ini
contains settings which are added by the missing plugin, so issuing an
error in that situation would be a problem. But a warning surely would be
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python