Your First Test#
Description#
This is the example of a simple test. Usually onetick test with otp consist of the following steps:
start a session
create
otp.Ticks
object with data for the querydescribe the query with otp syntax
execute the query
check the result (usually after conversion it to pandas DataFrame.)
Test code#
import pytest
import onetick.py as otp
from onetick.test.fixtures import m_session as session
def test_simple(session):
data = otp.sources.Ticks(dict(x=[1, 2, 3]))
df = data.to_dataframe()
assert all(df.x == [1, 2, 3])
Step-to-step#
Pytest has auto discovery feature, pytest doesn’t provide any configuration file, where you specify where your tests are, instead you should name them in special way. Follow the link above if you are not familiar with it.
Usually all tests are placed into the tests
folder. Create it in your project if still doesn’t have any tests folder.
In our example you should create a file, e.g. called test_example.py
in your project. And copy-paste the code from
Test code section. Save the file.
You then just run it with the following command:
$ pytest <you_project_dir>