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

use pytest in run_tests() #1129

Conversation

keitherskine
Copy link
Collaborator

The run_tests() utility has been updated so that it is now designed specifically to run the complete build tests. It can still be used for development testing but it will be relatively slow compared to python setup.py build_ext --inplace.

  1. run_tests() now uses pytest to run the build tests. Fortunately the unit tests scripts do not need to be changed for this (although they should eventually be converted from the unittest approach).
  2. A new requirements-test.txt file has been created for the necessary build test packages. This is currently just pytest.
  3. run_tests() now uses whatever pyodbc package is currently available (typically installed into a venv by tox). run_tests() doesn't look for any .pyd file anymore. For build testing, I'm hoping we can move away from the .pyd approach.
  4. tox has been enhanced so it can now retrieve database connection string info from a local configuration file set up by the user (default tmp/database.cfg although it can be overridden by PYODBC_DATABASE_CFG). Note, this is different from the existing default config file tmp/setup.cfg as mentioned in the unit test scripts. However, I do think it's better to use "setup.cfg" only for project configuration, not for any local development stuff.

Lastly, I'm very keen to move the unit test scripts into database-specific folders, in order to make test discovery easy. However, this will be tricky for Python 2.7 (which pytest doesn't support). I am creating a draft PR for that, which will act as a placeholder until we have dropped Python 2.7.

@keitherskine
Copy link
Collaborator Author

As an illustration of the output from tox now, here's an example:

C:\Users\toast\Documents\GitHub\forks\pyodbc>tox -- --sqlserver "DSN=localhost18;DATABASE=pyodbc"
unit_tests installed: attrs==22.1.0,colorama==0.4.6,exceptiongroup==1.0.4,iniconfig==1.1.1,packaging==21.3,pluggy==1.0.0,pyodbc @ file:///C:/Users/toast/Documents/GitHub/forks/pyodbc,pyparsing==3.0.9,pytest==7.2.0,tomli==2.0.1
unit_tests run-test-pre: PYTHONHASHSEED='170'
unit_tests run-test: commands[0] | python -m pip install --force-reinstall --no-deps .
Processing c:\users\toast\documents\github\forks\pyodbc
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pyodbc
  Building wheel for pyodbc (pyproject.toml) ... done
  Created wheel for pyodbc: filename=pyodbc-4.0.36b13+updaterun.tests.pytousepytest-cp310-cp310-win_amd64.whl size=66645 sha256=e3a5264987f23919e4f6a1992082c507d517c124bcb8bdb63dff8ea090b0c097
  Stored in directory: C:\Users\toast\AppData\Local\Temp\pip-ephem-wheel-cache-_zd2z1ef\wheels\6f\d5\25\c6588d92de4ca95e18a9938696a87dd94d6679b16bcbcc1f4f
Successfully built pyodbc
Installing collected packages: pyodbc
  Attempting uninstall: pyodbc
    Found existing installation: pyodbc 4.0.36b13+updaterun.tests.pytousepytest
    Uninstalling pyodbc-4.0.36b13+updaterun.tests.pytousepytest:
      Successfully uninstalled pyodbc-4.0.36b13+updaterun.tests.pytousepytest
Successfully installed pyodbc-4.0.36b13+updaterun.tests.pytousepytest
unit_tests run-test: commands[1] | python '.\tests3\run_tests.py' --sqlserver 'DSN=localhost18;DATABASE=pyodbc'
Running tests against SQL Server with connection string: DSN=localhost18;DATABASE=pyodbc
====================================================================================== test session starts ======================================================================================
platform win32 -- Python 3.10.8, pytest-7.2.0, pluggy-1.0.0
cachedir: .tox\unit_tests\.pytest_cache
rootdir: C:\Users\toast\Documents\GitHub\forks\pyodbc
collected 252 items

tests3\sqlservertests.py ................................................................................................................................................................. [ 63%]
...........................................................................................                                                                                                [100%]

====================================================================================== 252 passed in 3.04s ======================================================================================
____________________________________________________________________________________________ summary ____________________________________________________________________________________________
  unit_tests: commands succeeded
  congratulations :)

C:\Users\toast\Documents\GitHub\forks\pyodbc>

@keitherskine keitherskine merged commit 23ca23a into mkleehammer:master Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant