Skip to content

Commit

Permalink
Switched from nosetests to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
mikand committed Oct 20, 2020
1 parent 2a8b385 commit 6b2c216
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 47 deletions.
2 changes: 1 addition & 1 deletion ci/install_unix.sh
Expand Up @@ -85,7 +85,7 @@ fi
$PIP_INSTALL configparser
$PIP_INSTALL six
$PIP_INSTALL wheel
$PIP_INSTALL nose
$PIP_INSTALL pytest

if [ "${PYSMT_SOLVER}" == "cvc4" ]
then
Expand Down
2 changes: 1 addition & 1 deletion ci/run_unix.sh
Expand Up @@ -12,7 +12,7 @@ fi
${PYTHON} install.py --check

# Run the test suite
${PYTHON} -m nose pysmt -v # --with-coverage --cover-package=pysmt
${PYTHON} -m pytest pysmt -v # --with-coverage --cover-package=pysmt


# Test examples in examples/ folder
Expand Down
2 changes: 1 addition & 1 deletion ci/run_win.sh
Expand Up @@ -2,4 +2,4 @@
set -ev

python install.py --check
python -m nose -v
python -m pytest
2 changes: 1 addition & 1 deletion dev-requirements.txt
@@ -1,3 +1,3 @@
nose
pytest
wheel
six
12 changes: 6 additions & 6 deletions docs/development.rst
Expand Up @@ -64,13 +64,13 @@ Tests in pySMT are developed using python's built-in testing framework
and it should be possible to launch it by calling the file directly,
e.g.: ``$ python test_formula.py``.

However, the preferred way is to use nosetests, e.g.: ``$ nosetests pysmt/tests/test_formula.py``.
However, the preferred way is to use pytest, e.g.: ``$ python -m pytest pysmt/tests/test_formula.py``.

There are two utility scripts to simplify the testing of pysmt:
``run_tests.sh`` and ``run_all_tests.sh``. They both exploit
additional options for nosetests, such as parallelism and
timeouts. ``run_all_tests.sh`` includes all the tests that are
marked as ``slow``, and therefore might take some time to complete.
additional options for pytest, such as timeouts. ``run_all_tests.sh``
includes all the tests that are marked as ``slow``, and therefore
might take some time to complete.

Finally, tests are run across a wide range of solvers, versions of
python and operating systems using Travis CI. This happens
Expand Down Expand Up @@ -273,9 +273,9 @@ To test the package, we create a new hardcopy of the tests of pySMT:

0. ``mkdir -p test_pkg/pysmt``
1. ``cp -a github/pysmt/test test_pkg/pysmt/; cd test_pkg``
2. This should fail: ``nosetests -v pysmt``
2. This should fail: ``python -m pytest pysmt``
3. ``pip install --user github/dist/PySMT-a.b.c.tar.gz``
4. ``nosetests -v pysmt``
4. ``python -m pytest pysmt``
5. ``pip uninstall pysmt``

All tests should pass in order to make the release. Note: It is
Expand Down
4 changes: 1 addition & 3 deletions health_check.sh
@@ -1,6 +1,4 @@
#!/bin/bash

export PYTHONDONTWRITEBYTECODE=True
nosetests -A "not slow" \
--with-xunit \
--with-coverage --cover-html --cover-package=pysmt
python3 -mpytest -m "not slow"
8 changes: 4 additions & 4 deletions pysmt/test/smtlib/parser_utils.py
Expand Up @@ -29,11 +29,11 @@

# We use test generation in order to be able to obtain a separate
# test for each file.
# This is a feature of nosetest. The correct way to invoke these
# This is a feature of pytest. The correct way to invoke these
# tests is, e.g.,
# $ nosetests pysmt/test/smtlib/test_parser_qf_lra.py
# The function 'execute_script_fname' is a generator that
# returns the correct arguments for the test
# $ python -m pytest pysmt/test/smtlib/test_parser_qf_lra.py
# The function 'execute_script_fname' is a general checker that
# parses and invokes a solver for the given smt file
def execute_script_fname(smtfile, logic, expected_result):
"""Read and call a Solver to solve the instance"""

Expand Down
5 changes: 3 additions & 2 deletions pysmt/test/smtlib/test_fuzzed.py
Expand Up @@ -17,17 +17,18 @@
#
import os

import pytest

from six import StringIO

from nose.plugins.attrib import attr
from pysmt.shortcuts import reset_env
from pysmt.test import TestCase
from pysmt.smtlib.parser import SmtLibParser


class TestSmtLibParserFuzzer(TestCase):

@attr("slow")
@pytest.mark.slow
def test_fuzzed(self):
for fname in FUZZED_FILES:
script = self.parse(os.path.join(SMTLIB_DIR, fname))
Expand Down
10 changes: 8 additions & 2 deletions pysmt/test/smtlib/test_parser_lra.py
Expand Up @@ -16,12 +16,18 @@
# limitations under the License.
#
import os
import pytest

from pysmt.logics import LRA
from pysmt.test.smtlib.parser_utils import execute_script_fname, SMTLIB_TEST_FILES, SMTLIB_DIR


def test_generator():
def _get_tests():
for (logic, f, expected_result) in SMTLIB_TEST_FILES:
smtfile = os.path.join(SMTLIB_DIR, f)
if logic == LRA:
yield execute_script_fname, smtfile, logic, expected_result
yield smtfile, logic, expected_result

@pytest.mark.parametrize("smtfile, logic, expected_result", list(_get_tests()))
def test_lra(smtfile, logic, expected_result):
execute_script_fname(smtfile, logic, expected_result)
10 changes: 8 additions & 2 deletions pysmt/test/smtlib/test_parser_qf_arrays.py
Expand Up @@ -16,10 +16,16 @@
# limitations under the License.
#
import os
import pytest

from pysmt.test.smtlib.parser_utils import execute_script_fname, SMTLIB_TEST_FILES, SMTLIB_DIR

def test_generator():
def _get_tests():
for (logic, f, expected_result) in SMTLIB_TEST_FILES:
smtfile = os.path.join(SMTLIB_DIR, f)
if logic.theory.arrays:
yield execute_script_fname, smtfile, logic, expected_result
yield smtfile, logic, expected_result

@pytest.mark.parametrize("smtfile, logic, expected_result", list(_get_tests()))
def test_qf_arrays(smtfile, logic, expected_result):
execute_script_fname(smtfile, logic, expected_result)
11 changes: 9 additions & 2 deletions pysmt/test/smtlib/test_parser_qf_lia.py
Expand Up @@ -16,11 +16,18 @@
# limitations under the License.
#
import os
import pytest

from pysmt.logics import QF_LIA
from pysmt.test.smtlib.parser_utils import execute_script_fname, SMTLIB_TEST_FILES, SMTLIB_DIR

def test_generator():

def _get_tests():
for (logic, f, expected_result) in SMTLIB_TEST_FILES:
smtfile = os.path.join(SMTLIB_DIR, f)
if logic == QF_LIA:
yield execute_script_fname, smtfile, logic, expected_result
yield smtfile, logic, expected_result

@pytest.mark.parametrize("smtfile, logic, expected_result", list(_get_tests()))
def test_qf_lia(smtfile, logic, expected_result):
execute_script_fname(smtfile, logic, expected_result)
10 changes: 8 additions & 2 deletions pysmt/test/smtlib/test_parser_qf_lira.py
Expand Up @@ -16,11 +16,17 @@
# limitations under the License.
#
import os
import pytest

from pysmt.logics import QF_UFLIRA
from pysmt.test.smtlib.parser_utils import execute_script_fname, SMTLIB_TEST_FILES, SMTLIB_DIR

def test_generator():
def _get_tests():
for (logic, f, expected_result) in SMTLIB_TEST_FILES:
smtfile = os.path.join(SMTLIB_DIR, f)
if logic == QF_UFLIRA:
yield execute_script_fname, smtfile, logic, expected_result
yield smtfile, logic, expected_result

@pytest.mark.parametrize("smtfile, logic, expected_result", list(_get_tests()))
def test_qf_lira(smtfile, logic, expected_result):
execute_script_fname(smtfile, logic, expected_result)
10 changes: 8 additions & 2 deletions pysmt/test/smtlib/test_parser_qf_lra.py
Expand Up @@ -16,11 +16,17 @@
# limitations under the License.
#
import os
import pytest

from pysmt.logics import QF_LRA
from pysmt.test.smtlib.parser_utils import execute_script_fname, SMTLIB_TEST_FILES, SMTLIB_DIR

def test_generator():
def _get_tests():
for (logic, f, expected_result) in SMTLIB_TEST_FILES:
smtfile = os.path.join(SMTLIB_DIR, f)
if logic == QF_LRA:
yield execute_script_fname, smtfile, logic, expected_result
yield smtfile, logic, expected_result

@pytest.mark.parametrize("smtfile, logic, expected_result", list(_get_tests()))
def test_qf_lra(smtfile, logic, expected_result):
execute_script_fname(smtfile, logic, expected_result)
10 changes: 8 additions & 2 deletions pysmt/test/smtlib/test_parser_qf_nia.py
Expand Up @@ -16,11 +16,17 @@
# limitations under the License.
#
import os
import pytest

from pysmt.logics import QF_NIA
from pysmt.test.smtlib.parser_utils import execute_script_fname, SMTLIB_TEST_FILES, SMTLIB_DIR

def test_generator():
def _get_tests():
for (logic, f, expected_result) in SMTLIB_TEST_FILES:
smtfile = os.path.join(SMTLIB_DIR, f)
if logic == QF_NIA:
yield execute_script_fname, smtfile, logic, expected_result
yield smtfile, logic, expected_result

@pytest.mark.parametrize("smtfile, logic, expected_result", list(_get_tests()))
def test_qf_nia(smtfile, logic, expected_result):
execute_script_fname(smtfile, logic, expected_result)
10 changes: 8 additions & 2 deletions pysmt/test/smtlib/test_parser_qf_nra.py
Expand Up @@ -16,11 +16,17 @@
# limitations under the License.
#
import os
import pytest

from pysmt.logics import QF_NRA
from pysmt.test.smtlib.parser_utils import execute_script_fname, SMTLIB_TEST_FILES, SMTLIB_DIR

def test_generator():
def _get_tests():
for (logic, f, expected_result) in SMTLIB_TEST_FILES:
smtfile = os.path.join(SMTLIB_DIR, f)
if logic == QF_NRA:
yield execute_script_fname, smtfile, logic, expected_result
yield smtfile, logic, expected_result

@pytest.mark.parametrize("smtfile, logic, expected_result", list(_get_tests()))
def test_qf_nra(smtfile, logic, expected_result):
execute_script_fname(smtfile, logic, expected_result)
10 changes: 8 additions & 2 deletions pysmt/test/smtlib/test_parser_qf_ufbv.py
Expand Up @@ -16,11 +16,17 @@
# limitations under the License.
#
import os
import pytest

from pysmt.logics import QF_UFBV
from pysmt.test.smtlib.parser_utils import execute_script_fname, SMTLIB_TEST_FILES, SMTLIB_DIR

def test_generator():
def _get_tests():
for (logic, f, expected_result) in SMTLIB_TEST_FILES:
smtfile = os.path.join(SMTLIB_DIR, f)
if logic <= QF_UFBV:
yield execute_script_fname, smtfile, logic, expected_result
yield smtfile, logic, expected_result

@pytest.mark.parametrize("smtfile, logic, expected_result", list(_get_tests()))
def test_qf_ufbv(smtfile, logic, expected_result):
execute_script_fname(smtfile, logic, expected_result)
4 changes: 2 additions & 2 deletions pysmt/test/test_cnf.py
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#
import os
from nose.plugins.attrib import attr
import pytest

from pysmt.shortcuts import Implies, is_sat, reset_env, Symbol, Iff
from pysmt.rewritings import CNFizer
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_smtlib_cnf_small(self):
if cnt == max_cnt:
break

@attr("slow")
@pytest.mark.slow
@skipIfNoSolverForLogic(QF_UFLIRA)
def test_smtlib_cnf(self):
for (logic, f, expected_result) in SMTLIB_TEST_FILES:
Expand Down
7 changes: 4 additions & 3 deletions pysmt/test/test_simplify.py
Expand Up @@ -15,7 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from nose.plugins.attrib import attr
import pytest

from pysmt.test import TestCase, skipIfSolverNotAvailable, main
from pysmt.test.examples import get_example_formulae
from pysmt.environment import get_env
Expand All @@ -29,7 +30,7 @@

class TestSimplify(TestCase):

@attr("slow")
@pytest.mark.slow
@skipIfSolverNotAvailable("z3")
@skipIfSolverNotAvailable("cvc4")
def test_simplify_qf(self):
Expand All @@ -44,7 +45,7 @@ def test_simplify_qf(self):
msg="Simplification did not provide equivalent "+
"result:\n f= %s\n sf = %s" % (f, sf))

@attr("slow")
@pytest.mark.slow
@skipIfSolverNotAvailable("z3")
def test_simplify_q(self):
simp = get_env().simplifier
Expand Down
4 changes: 1 addition & 3 deletions run_all_tests.sh
Expand Up @@ -17,12 +17,10 @@
# limitations under the License.
#

#export NOSE_PROCESSES=-1
#export NOSE_PROCESS_TIMEOUT=360
export PYTHONDONTWRITEBYTECODE=True

# Exit on error (-x)
# Rule of thumb: if a test takes more than 10 seconds it
# should be marked as slow using:
# @attr("slow")
python3 -m nose -v -x pysmt/test
python3 -m pytest -x pysmt/test
6 changes: 2 additions & 4 deletions run_tests.sh
Expand Up @@ -17,13 +17,11 @@
# limitations under the License.
#

#export NOSE_PROCESSES=-1
#export NOSE_PROCESS_TIMEOUT=240
export PYTHONDONTWRITEBYTECODE=True

# Skip slow tests (-A "not slow")
# Skip slow tests (-m "not slow")
# Exit on error (-x)
# Rule of thumb: if a test takes more than 10 seconds it
# should be marked as slow using:
# @attr("slow")
python3 -m nose -v -A "not slow" -x pysmt/test
python3 -m pytest -m "not slow" -x pysmt/test

0 comments on commit 6b2c216

Please sign in to comment.