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

Switch from nose to pytest #58

Closed
scasagrande opened this issue Jan 14, 2016 · 5 comments
Closed

Switch from nose to pytest #58

scasagrande opened this issue Jan 14, 2016 · 5 comments

Comments

@scasagrande
Copy link
Contributor

It has come to my attention that the test framework nose (including nose2) is not being as actively developed as py.test. It has a lot more features and nicer output. It also claims to support nose-tests straight out of the box. I believe the only thing we will need to do is replace any nose.eq_ calls with just straight assert statements, as well as update travis & docs.

https://github.com/pytest-dev/pytest/
http://pytest.org/latest/

Trello card: https://trello.com/c/VHzlJk2U/11-switch-test-framework-from-nose-to-py-test

Acceptance Criteria

  • Tests run and pass using the pytest framework
  • Travis updated
  • Dev docs updated
  • dev-requirements.txt updated
@bilderbuchi
Copy link
Contributor

bilderbuchi commented Jul 14, 2017

OK, so I took a first stab at this (on Python 3.6).

  • I fixed the mock import occurences to import mock from instruments.tests, where I have placed an import guard to choose the stdlib mock that's available in Python>=3.3
  • I realised that the dependency on pyserial is actually pyserial>=3.3, since you are using list_ports_common. (which is a little problem since Anaconda/conda-forge only has pyserial 2.7)
  • With those changes, and nose installed, pytest runs the same 675 tests, and succeeds, as nosetests. So, as long as nose is installed, people can already use pytest
  • Nose functionality used is @raises, eq_ and nottest (once).
    • eq_ I think is easy to replace with a nice regular expression search/replace: basically, eq_(a,b) to assert a == b.
    • nottest occurs only once, so probably not much effort to replace.
    • @raises decorator is used 161 times, and is more tedious to replace, since pytest uses this with a context manager.

@scasagrande
Copy link
Contributor Author

Neat, thanks for taking a look.

I forgot about the pyserial minimum version requirement. There is some more stuff in PR that uses newer features of pyserial, so I'll have to think about what to do there.

@bilderbuchi
Copy link
Contributor

Optimally, we should find out how much effort it is to create a conda-forge recipe for pyserial, then the min version won't be a problem. I think the pymeasure folks have tried this before, correct @cjermain?

@bilderbuchi
Copy link
Contributor

update: Recently, a current version of pyserial has become available on conda-forge, so that can be installed via conda now.

@bilderbuchi
Copy link
Contributor

So, this was a lot of manual work, but I have created a PR (#183).

bilderbuchi added a commit to bilderbuchi/InstrumentKit that referenced this issue Mar 17, 2018
bilderbuchi added a commit to bilderbuchi/InstrumentKit that referenced this issue Mar 17, 2018
bilderbuchi added a commit to bilderbuchi/InstrumentKit that referenced this issue Mar 17, 2018
scasagrande pushed a commit that referenced this issue Mar 24, 2018
* Use mock from the standard lib if available.

* Migrate nose raises to pytest.raises.

This touches a lot of code because pytest.raises
is used in a context manager, so indentation
has to be changed.

Replacement happened with regex from
@raises\((.*)\) to @pytest.mark.xfail(raises=$1)
then from @pytest.mark.xfail\(raises=(.*)\)\ndef(.*)
to def$2\n    with pytest.raises($1):
then manual correction of indentation.

* Replace nose eq_ by assert, remove nottest.

* Move CI from nosetests to pytest, adapt docs.

Pin astroid version, too, to avoid wrong errors on CI.

* Fix some introduced errors flagged by pylint.

* Specify minimum pyserial requirement (see #58).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants